title: Releasing event handlers for dynamically created items
body: <p>I'm populating a <code>ToolStripMenu</code> with entries from an <code>XML</code> file.  Each <code>ToolStripItem</code> added to the menu automatically gets about a dozen event handlers assigned to it.  The user has the option to change the <code>XML</code> and refresh the menu, which clears everything using: </p>
  
  <pre><code>menuStrip1.Items.Clear();
  </code></pre>
  
  <p>This repopulates from the <code>XML</code> and refreshes the Form.  It appears that the event handlers for all these dynamic items are never removed from memory.  Most of the items don't sit directly on menuStrip1 but in dynamically created submenus which reside on <code>menuStrip1</code>.  </p>
  
  <p>Nevertheless, I can sit there refreshing the Form and the memory just balloons out of control, adding <code>5-10 MB</code> per refresh of about <code>100 dynamic ToolStripItems.</code>  It can quickly reach hundreds of MB which crashes the application.</p>
  
  <p>The <code>ToolStripItems</code> also load other things such as properties and icons, but it seems to be the event handlers which use most of the added memory.  I commented out all the handlers and the memory became far more (but not completely) sustainable with each refresh.</p>
  
  <p>Is it necessary to enumerate through all the menus and submenus and individually release each event handler to assure it's not sticking around?</p>