Jump to content

Memory leak with GUICtrlSendMsg and Picture control


Go to solution Solved by Andreik,

Recommended Posts

$img = GUICtrlCreatePic("", 500,0,1390,890)

    ...

    _GDIPlus_Startup()
    local $bitmap_1 = _GDIPlus_BitmapCreateFromMemory(InetRead($jpg_url))
    local $bitmap_2 = _GDIPlus_ImageResize ($bitmap_1, 1390, 890)
    local $bitmap_3 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bitmap_2)
    GUICtrlSendMsg($img, 0x0172, 0, $bitmap_3)

    _GDIPlus_BitmapDispose($bitmap_1)
    _GDIPlus_BitmapDispose($bitmap_2)
    _WinAPI_DeleteObject($bitmap_3)
    _GDIPlus_Shutdown()

I think this is all the relevant code. I've never worked with any of these functions before (aside from GUICtrlCreatePic and setting it to a picture file, not setting it via memory via GUICtrlSendMsg) so I don't know how to clean up properly after loading/drawing an image to screen. I commented out everything and went line by line figuring out what stops the leak. BitmapDispose and DeleteObject work for the varables I created... $bitmap_1, 2, 3 are good. Now all that remains is the  GUICtrlSendMsg line of code. When I comment just this line, the memory leak stops. Do I need to do something to clear the picture control? Or send a message to $img using GUICtrlSendMsg telling it to clear the previous image? The docs for the function don't show anything (https://www.autoitscript.com/autoit3/docs/functions/GUICtrlSendMsg.htm) but I see it's being used to start/stop a marquee scrolling text for a progress bar control with the third parameter value 0/1... I tried this with Pic control thinking making 0 is for displaying the bitmap, and 1 is for clearing it, but it doesn't clear the memory.

Help would be appreciated, thanks.

Edited by lIlIIlIllIIIIlI
more info
Link to comment
Share on other sites

  • Solution
Posted (edited)

You need to delete the object returned by GUICtrlSendMsg().

_WinAPI_DeleteObject(GUICtrlSendMsg($img, 0x0172, 0, $bitmap_3))

 

Quote

Do I need to do something to clear the picture control? Or send a message to $img using GUICtrlSendMsg telling it to clear the previous image? The docs for the function don't show anything (https://www.autoitscript.com/autoit3/docs/functions/GUICtrlSendMsg.htm) but I see it's being used to start/stop a marquee scrolling text for a progress bar control with the third parameter value 0/1... I tried this with Pic control thinking making 0 is for displaying the bitmap, and 1 is for clearing it, but it doesn't clear the memory.

The message you send to the control is STM_SETIMAGE and doesn't star/stop anything but set a new image. The third parameter is IMAGE_BITMAP and specifies the type of image to associate with the control. Also the return value is a handle to the image previously associated with the control (or NULL) so it must be deleted properly.

Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

7 hours ago, Andreik said:

You need to delete the object returned by GUICtrlSendMsg().

_WinAPI_DeleteObject(GUICtrlSendMsg($img, 0x0172, 0, $bitmap_3))

 

The message you send to the control is STM_SETIMAGE and doesn't star/stop anything but set a new image. The third parameter is IMAGE_BITMAP and specifies the type of image to associate with the control. Also the return value is a handle to the image previously associated with the control (or NULL) so it must be deleted properly.

Ah, the function returns something! That makes so much sense, thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...