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.
Here is my code
Dim imageB As New ImageBrush
imageB.ImageSource = Me.GetImageSource(My.Resources.checkImage)
My.Resources.checkImage.Dispose()
Me.mainCanvas.Background = imageB
and here is the method GetImageSource():
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
Any ideas ? Thanks.