Unregistered event handlers cause memory leak

故事扮演 提交于 2019-11-30 07:11:02

First off, just to prove the point, try logging the adding and removal of events to a simple text file. Then, check how many were added vs removed.

It sounds as if there is a bug somewhere in the business logic which is not unregistering the event in all circumstances.

The Dispose method on the collection should be called directly by your code because the event holds a reference to the collection. Your collection will never be destroyed by garbage collector.

You should also change the behaviour of the Remove and Clean methods of the collection to detach the event handler from the removed items.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!