Home > Windows API > GetIconInfo caveat!

GetIconInfo caveat!

I had heavy resource leaks in my resource digger application with my resource leak detector showing ever increasing amount of bitmap handles!

As a hint to me this was happening in my icon display function, but looking up the code I found nothing causing a leak. Analyzing closely I found that bitmap count was increasing by two, ah immediately it struck me, it’s GetIconInfo! It creates two bitmap and I was not deleting them, my fault I should’ve have read MSDN properly!. 😦

So as a summary don’t forget to delete bitmaps in an ICONINFO structure filled out by GetIconInfo because this is what the documentation says…

MSDN:

GetIconInfo creates bitmaps for the hbmMask and hbmColor members of ICONINFO. The calling application must manage these bitmaps and delete them when they are no longer necessary. 😦

For those of you who didn’t know about GetIconInfo, it’s just a function which returns mask bitmap and real bitmap for an icon. You see transparent icons because they have a mask bitmap associated with them. This function also tells us whether given icon handle represents an icon or a cursor along with hotspot co-ords for a cursor.

Advertisements
  1. May 9, 2008 at 12:05 pm

    Any links to it PP? I use a tool called Bear.exe, it’s a freeware tool, quite good.

  2. PP
    May 9, 2008 at 8:06 am

    John, We’ve had good luck with MemoryValidator in tracking down GDI leaks. -PP

  3. April 9, 2008 at 3:09 am

    Thanks John!

  4. April 8, 2008 at 5:50 pm

    Good tip!

    Can you recommend any tools for tracking GDI leaks these days? Long ago, we used BoundChecker for this and I do have a copy of the occasionally-useful GDI Leak Tracker from the MSJ/MSDN article looong ago but I think it needs work to be brought up to date and a 64-bit version would be nice. I’m left with the less-than-ideal technique of watching the GDI/USER columns in Process Explorer or taskmgr.

    John

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: