title: WPF CreateBitmapSourceFromHBitmap() memory leak
body: <p>I need to draw an image pixel by pixel and display it inside a WPF.  I am attempting to do this by using a <code>System.Drawing.Bitmap</code> then using <code>CreateBitmapSourceFromHBitmap()</code> to create a <code>BitmapSource</code> for a WPF Image control.  I have a memory leak somewhere because when the <code>CreateBitmapSourceFromBitmap()</code> is called repeatedly the memory usage goes up and does not drop off until the application is ended.  If I don't call <code>CreateBitmapSourceFromBitmap()</code> there is no noticeable change in memory usage.</p>
  
  <pre><code>for (int i = 0; i &lt; 100; i++)
  {
      var bmp = new System.Drawing.Bitmap(1000, 1000);
      var source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
          bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty,
          System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
      source = null;
      bmp.Dispose();
      bmp = null;
  }
  </code></pre>
  
  <p>What can I do to free the <code>BitmapSource</code> memory?</p>