Apr 082008

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…


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 Responses to “GetIconInfo caveat!”

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

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

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


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.