Unregistered event handlers cause memory leak

前端 未结 2 1560
有刺的猬
有刺的猬 2020-12-30 10:52

I\'m maintaining a web application that has a memory leak.

Based on my investigation using Red Gate ANTS memory profiler I\'m pretty sure that the memory leak is cau

相关标签:
2条回答
  • 2020-12-30 11:06

    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.

    0 讨论(0)
  • 2020-12-30 11:18

    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.

    0 讨论(0)
提交回复
热议问题