DockletLoadGDIPlusImage Memory Leak?

I'm currently writing a docklet and as part of my configuration dialog I am attempting to load an image to a static picture control but I noticed there was a memory leak.

Anyway to cut a long story short, I cut all the code down to the bare minimum and isolated the leak to the call to DockletLoadGDIPlusImage - now all I have in the method call I am making is the following:

void LoadImageIDC_CLOCK(DOCKLET_DATA *lpData, HWND hDlg)
{
Bitmap *bmpHandle = DockletLoadGDIPlusImage(lpData->szImage);
DeleteObject(bmpHandle);
}

If i comment those 2 lines of code out there is no memory leak.

Can you confirm this is a leak in that call and if there is a fix for it?
1,751 views 1 replies
Reply #1 Top
Ignore this post - fixed it.

Pretty new to GDI and certainly out of practice with unmanaged frameworks (I'm used to C#, Java, Rails, etc...)

Rather than call DeleteObject (which according to the documentation should release all resources related to a bitmap) I simply use the delete keyword instead. Strange thing is delete keyword on a HBITMAP doesn't work and for that I have to use DeleteObject(). So the following code does demonstrate that there is no leak:

void LoadImageIDC_CLOCK(DOCKLET_DATA *lpData, HWND hDlg)
{
for( int i = 0 ; i < 100 ; i++)
{
Bitmap *bmpHandle = DockletLoadGDIPlusImage(lpData->szImage);
HBITMAP hBitmap;
bmpHandle->GetHBITMAP(Color(0, 0, 0), &hBitmap);
DeleteObject(hBitmap);
delete bmpHandle;
}
}