I've always been a bit puzzled about the business of creating and destroying GDI objects like pens and brushes and bitmaps. Some examples I have seen create GDI objects but do not appear to delete them. Others do.
I was wondering if there was some mechanism under Visual Studio whereby you can monitor the number of GDI resources your app has allocated and check to see if you are tidying up properly before leaving certain procedures. Something similar to the way in which VS can tell you if you have a memory leak.
One easy thing to do is add "GDI Objects" column to task manager (or process explorer). Then see if this number just continues to grow as you use your program.
As codeplug says, the easiest thing to do, is start up Task Manager and set it to display GDI Objects, then you can see if you are leaking any. I just did that a few days ago, and found I was, so downloaded a utility from Software Verification Limited, at www.softwareverify.com, called Memory Validator. It keeps track of where GDI objects are created, then lets you know if they aren't destroyed. If you run it on a debug version of the app, you'll get a listing and line-number for the offending CreateObject.
It comes with a 30 day free trial, so if you work fast you may not need to buy it...
Bookmarks