I have a simple code which seems to cause a memory leak for me:
Public Function NewAlphaBitmap(ByVal uWidth As Integer, ByVal uHeight As Integer) As Bitmap
Return New Bitmap(uWidth, uHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
End Function
After a few loops of this...
Dim nBmp As Bitmap
For i As Integer = 0 To 1000
nBmp = NewAlphaBitmap(5000, 5000)
Next
... I get an Out Of Memory error.
In my understanding, nBmp should automatically be disposed when I set it to a new Bitmap using NewAlphaBitmap, so there shouldn't be a memory leak.
But seemingly this isn't so.
What might be the problem here?
Edit:
The memory leak even persists when I do the following:
For i As Integer = 0 To 1000
nBmp = NewAlphaBitmap(5000, 5000)
nBmp = Nothing
Next