0

This question already has an answer here:

I am developing a big WinForm application and experiencing some memory leaks. One of the problems was closing the form did not free up memory (I used .NET Memory Profiler). Some people suggested that event handlers should be removed from the form manually to prevent memory leaks. Does it mean I need to remove Load, Form_Closing event handlers that were created by the designer when the form is being closed? I am using .NET 4.5. Thank you!

1 답변


-1

No. The concern with event handlers is that the object that executes the handler is referenced by the object with the method, meaning that if the object that fires the event will end up living for a lot longer than the object with the handler that the object with the handler cannot be cleaned up.

There is no issue at all with the object firing the event having a much shorter lifetime than the object handling the event, because the object handling the event doesn't have a reference to the object firing the event.

Linked


Related

Latest