I analyze a VB.NET project and there are some objects (child MDI form) that are disposed, but not removed by the GC.
The MemoryProfiler analysis find, among others, the following:
"This instance is disposed and still indirectly rooted by an EventHandler. This often indicates that the EventHandler has not been properly removed and is a common cause of memory leaks. The instances below are directly rooted by EventHandler(s). Investigate them to get more information about this issue..."
Now, I try to figure out what should this mean and how to fix it.
I have a MDI form and a child form. The child form is not collected by the GC after a open/close, apparently because remains still (indirectly?) referenced by the MDIForm EventHandlerList
...
What can it be and how do I to fix it?
I tried the fix recommended in this thread, because had a problem with the MDI reference in the PropertyStore
, now this eliminated, but appeared the MDI EventHandlerList
reference to the child form...
After some code analysis I observed some
AddHandler newMenu.Click, AddressOf ClickMenu
without preceding with RemoveHandler newMenu.Click, AddressOf ClickMenu
. Could it be the main cause?
And, a propos, is the Handles
Private Sub ClickMenu(sender as Object, e as EventArgs) Handles newMenu.Click
better that
RemoveHandler newMenu.Click, AddressOf ClickMenu
AddHandler newMenu.Click, AddressOf ClickMenu
from the memory allocation point of view?