GDI + general error: memory leak using VB.NET

I have a memory leak problem with my code using images from VB.NET and WPF. Even if I delete bitmap objects, the memory does not 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 GetImageSource () method:

 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.

+1
source share

Source: https://habr.com/ru/post/1390677/


All Articles