dinsdag 8 maart 2011

Denomo: GDI handle leak check for Delphi

Last week I had to find an anoying GDI handle leak in one of the touch panel apps of my current customer. After some time it ran out of resources.

I started ProcesExplorer, double clicked on the touch panel process (so I could watch the number of GDI handles) and clicked through some screens of the application. I saw a growing GDI counter...

Next I placed some breakpoints and stepped through the code to find out where it came from. It took me quite some time, but I finally found it (of course: in a place I did not expect :-) a TBitmap was created for a button everytime but never released).

Next day, I got the same bug issue in another application. So I started thinking how to speed up finding these kind of leaks. I knew there was an application that could do it for me, but I could not find it back on internet. But after some googling I found a Delphi project: Denomo. It detours a number of Windows API's, like CreateBitmap, CreateBrush, etc and generates a list of unreleased handles and a stack trace per handle (where it was created) when you close your applicaiton.
However, it was not (unicode) compatible with Delphi 2010, and it needed a dll to run and a remote control app for the logging.

I made some small changes to make it compatible with Delphi 2010 (unicode, at least for the parts I needed) and made it standalone (no dll + remote control needed):
http://code.google.com/p/asmprofiler/source/browse/trunk/EXT/Denomo/
I also made a small demo/test project:
http://code.google.com/p/asmprofiler/source/browse/trunk/EXT/Denomo/gdileaktest/Project7.dpr

Now I can find GDI handle leaks very easy!

1 opmerking:

Wang Qi zei

Hi,

Thanks for your post and glad to see Denomo is useful to you.

Can you tell me what changes you made to make it compatible with Delphi 2010?

Supporting Unicode should be not difficult.

Qi -- kbasm.com