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.

4 thoughts on “GetIconInfo caveat!

  1. 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

Appreciate your comments...