title: Memory leaks in WPF/C#
body: <p>Please note this is done in <code>WPF/C#</code> and not in <code>.net2.0</code> <code>Winforms</code></p>
  
  <p>I have a ListBox which contains objects of say <code>Class X</code>. Class X contains a <code>BitmapSource</code> object which is displayed in the listbox, so it displays similar to <code>[Image] [Text]</code></p>
  
  <p>This is loaded via the use of the <code>CreateBitmapSourceFromHBitmap</code> - note also that I call <code>DeleteHBitmap</code> to delete the handle of the <code>HBitmap</code> during this call, which is well known to do from posts I've seen on google/etc</p>
  
  <p>I have a tree which contains said <code>ListBox</code> in each <code>TreeViewItem</code> - typically the tree has several items loaded. Users can drag/drop these images into different TreeViewItems. To handle these operation I manually call the operations: </p>
  
  <pre><code>&lt;code&gt;
      ItemCollection.RemoveAt
  &lt;/code&gt;
  
  &lt;code&gt;
      ItemCollection.Insert
  &lt;/code&gt;
  </code></pre>
  
  <p>to <code>move</code> the images from the ListBox item collection, note when I insert I create a new <code>Class X</code> object to insert into the <code>ListBox</code> item collection</p>
  
  <p>I have noticed I get a consistent memory leak from calling such operations several times, over the space of 5-10 mins of consistent dragging and dropping.</p>
  
  <p>My question is: </p>
  
  <p>Am I handling the moving of the <code>BitmapSource</code>'s correctly? Is there something I'm doing to cause the Images to not be fully removed from the <code>ItemCollection</code>?</p>
  
  <p>Or is there something fundamental I've missed?</p>