I am analyzing a VB.NET project and some objects (child MDIs ) that are located but not deleted using GC .
The MemoryProfiler analysis finds, among other things, the following:
"This instance is located and remains indirectly associated with EventHandler. This often indicates that EventHandler was not properly and is a common cause of memory leak. The following are examples directly related to EventHandler (s). Study them to get more information about this problem ... "
Now I'm trying to understand what this means and how to fix it.
I have an MDI form and a child form. The detailed form is not collected by the GC after opening / closing, apparently because it remains stationary (indirectly?) Referenced by MDIForm EventHandlerList ...
What could it be and how to fix it?
I tried the fix recommended in this thread , because I had a problem with the MDI link in the PropertyStore , now it is fixed, but the MDI EventHandlerList link to the child form appeared ...
After some code analysis, I noticed some
AddHandler newMenu.Click, AddressOf ClickMenu
without the previous RemoveHandler newMenu.Click, AddressOf ClickMenu . Could this be the main reason?
And, the suggestion is Handles
Private Sub ClickMenu(sender as Object, e as EventArgs) Handles newMenu.Click
better than
RemoveHandler newMenu.Click, AddressOf ClickMenu AddHandler newMenu.Click, AddressOf ClickMenu
from the memory allocation point?