title: GDI+ generic error : memory leak using VB.NET
body: <p>I got a memory leak problem with my code, using images with VB.NET and WPF. Even if I dispose my bitmap objects, the memory doesn't stop growing. </p>
  
  <p>Here is my code</p>
  
  <pre><code>Dim imageB As New ImageBrush                
  imageB.ImageSource = Me.GetImageSource(My.Resources.checkImage)
  My.Resources.checkImage.Dispose()
  Me.mainCanvas.Background = imageB
  </code></pre>
  
  <p>and here is the method GetImageSource():</p>
  
  <pre><code>Public Function GetImageSource(ByVal bmp As System.Drawing.Bitmap) As ImageSource
      Dim imageSource As BitmapSource
      Dim hbitmap As IntPtr = bmp.GetHbitmap
      Dim sizeOptions As BitmapSizeOptions = BitmapSizeOptions.FromEmptyOptions()
      imageSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, Int32Rect.Empty, sizeOptions)
      ImageSource.Freeze()
      DeleteObject(hbitmap)
      bmp.Dispose()
      Return imageSource
  End Function
  </code></pre>
  
  <p>Any ideas ?
  Thanks.</p>