hello does anyone know why GdipCreateBitmapFromScan0 causes memory leak, next a very simple example with a timer calling the function and removing the image.
In the task manager you can see how VB6.exe gradually increases its memory
Code:Option Explicit Private Declare Sub GdiplusShutdown Lib "gdiplus" (ByVal Token As Long) Private Declare Function GdiplusStartup Lib "gdiplus" (Token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As Long Private Declare Function GdipDisposeImage Lib "gdiplus" (ByVal Image As Long) As Long Private Declare Function GdipCreateBitmapFromScan0 Lib "GdiPlus.dll" (ByVal Width As Long, ByVal Height As Long, ByVal stride As Long, ByVal PixelFormat As Long, scan0 As Any, BITMAP As Long) As Long Private Type GdiplusStartupInput GdiplusVersion As Long DebugEventCallback As Long SuppressBackgroundThread As Long SuppressExternalCodecs As Long End Type Private Const PixelFormat32bppPARGB As Long = &HE200B Private Const GDIP_OK As Long = 0& Dim GdipToken As Long Private Sub Form_Load() Dim GdipStartupInput As GdiplusStartupInput GdipStartupInput.GdiplusVersion = 1& Call GdiplusStartup(GdipToken, GdipStartupInput, ByVal 0&) Timer1.Interval = 100 End Sub Private Sub Timer1_Timer() Dim hImage As Long If GdipCreateBitmapFromScan0(16&, 16&, 0&, PixelFormat32bppPARGB, ByVal 0&, hImage) = GDIP_OK Then Debug.Print hImage GdipDisposeImage hImage End If End Sub Private Sub Form_Unload(Cancel As Integer) Call GdiplusShutdown(GdipToken) End Sub




Reply With Quote