CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Location
    Toronto, Canada
    Posts
    108

    How to detect GDI Resource Leaks

    Greetings:

    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.

    Thank you,
    Mark

  2. #2
    Join Date
    Nov 2003
    Posts
    1,902

    Re: How to detect GDI Resource Leaks

    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.

    More info:
    http://msdn.microsoft.com/en-us/magazine/cc301756.aspx

    Don't know what (if any) Visual Studio may have integrated for GDI leak detection.

    >> ... but do not appear to delete them. Others do.
    You can always look up the relevant API's on MSDN to see if you should be destroying something.

    gg

  3. #3
    Join Date
    Aug 2008
    Location
    Scotland
    Posts
    379

    Re: How to detect GDI Resource Leaks

    Hi,

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

    Cheers,
    Alan

  4. #4
    Join Date
    Apr 2004
    Location
    Toronto, Canada
    Posts
    108

    Re: How to detect GDI Resource Leaks

    Thanks to both of you.

    I downloaded that GDIDEBUG program from the MSDN web site and tried that. It told me what I needed to know.

    Cheers!
    Mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured