title: Event handler and memory leaks
body: <p>I analyze a VB.NET project and there are some objects (child <a href="https://en.wikipedia.org/wiki/Multiple_document_interface" rel="nofollow noreferrer">MDI</a> form) that are disposed, but not removed by the <a href="http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29" rel="nofollow noreferrer">GC</a>.</p>
  
  <p>The MemoryProfiler analysis find, among others, the following: </p>
  
  <blockquote>
    <p>"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..."</p>
  </blockquote>
  
  <p>Now, I try to figure out what should this mean and how to fix it. </p>
  
  <p>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 <code>EventHandlerList</code>...</p>
  
  <p>What can it be and how do I to fix it?</p>
  
  <p>I tried the fix recommended in <a href="https://stackoverflow.com/questions/1117983/about-propertystore-and-mdi-child-form/1533968#1533968">this thread</a>, because had a problem with the MDI reference in the <code>PropertyStore</code>, now this eliminated, but appeared the MDI <code>EventHandlerList</code> reference to the child form...</p>
  
  <p>After some code analysis I observed some</p>
  
  <pre><code>AddHandler newMenu.Click, AddressOf ClickMenu
  </code></pre>
  
  <p>without preceding with <code>RemoveHandler newMenu.Click, AddressOf ClickMenu</code>. Could it be the main cause?</p>
  
  <p>And, a propos, is the <code>Handles</code></p>
  
  <pre><code>Private Sub ClickMenu(sender as Object, e as EventArgs) Handles newMenu.Click
  </code></pre>
  
  <p>better that</p>
  
  <pre><code>RemoveHandler newMenu.Click, AddressOf ClickMenu
  AddHandler newMenu.Click, AddressOf ClickMenu
  </code></pre>
  
  <p>from the memory allocation point of view?</p>