Click here to Skip to main content
13,835,377 members
Click here to Skip to main content
Add your own
alternative version


27 bookmarked
Posted 31 Mar 2003

Leak Checking for GDI+

, 31 Mar 2003
Rate this:
Please Sign up or sign in to vote.
Describes how to check your app for GDI+ leaks


We all know about MFC's memory leak detection, that famous #define new DEBUG_NEW at the beginning of each source code file. But there's nothing similar for GDI+, until now!

  1. You'll need the checked build of GDI+, which is found in the ASMS\1000\MSFT\WINDOWS\GDIPLUS folder of the Checked Windows XP CD.
  2. You'll need to build a version (debug or release) of your app WITHOUT the manifest.  The quickest way to do this is to simply add a symbol in the properties for the manifest so it isn't included in the build.  If your app doesn't have a manifest, then just don't worry.

    (Click here to read about manifests, or search for the text Manifest Resources on MSDN.)
  3. Install WinDGB from here (or search for the text Debugging Tools on MSDN)
  4. Create a copy of your executable and append .local to the name, so it looks like this - MyProj.exe.local
  5. Copy the checked (also know as debug) version of GDIPLUS.DLL to your project's executable directory.
  6. Now run WinDBG and go to "File/Open Executable..." and open the EXE, then hit F5 and play with your app. 
    Note: Make sure that GDIPLUS.DLL is loaded from your project's directory by verifying the loaded modules list in WinDBG.

Once you've played with the app for a while, exit and observe the output in WinDBG.  Leaks will be shown like this :-

WRN mem.cpp(385): Address- --Size-- API TAG  -Caller- -Line- File
WRN mem.cpp(406): 00D36AA0      584     unkn 00D36AAC     91 engine\runtime\mem.h 
        <=== LEAK!!!!!
WRN mem.cpp(406): 00D368E0      424     unkn 00D368EC     91 engine\runtime\mem.h
WRN mem.cpp(406): 00D367A0      296 API unkn 00D367AC  12191 engine\flat\flatapi.cpp
WRN mem.cpp(406): 00D36388      584     unkn 00D36394     91 engine\runtime\mem.h
WRN mem.cpp(406): 00D361C8      424     unkn 00D361D4     91 engine\runtime\mem.h
WRN mem.cpp(406): 00D36088      296 API unkn 00D36094  12191 engine\flat\flatapi.cpp
RIP mem.cpp(422): Memory leaks detected.
List header (gdiplus!gpmemAllocList) at 00D36AA0
Use: dt AllocTrackHeader [address] to display the memory block headers.
Use: dds [AllocTrackHeader.caller_address] to display the allocation stack.

(This output was generated by the sample project included with this article.  I allocate a Pen, but never release it.)

To find the source code location of this leak, simply use the dds command followed by the -Caller- address, like this...

dds 00D36AAC

WinDBG will then find the code location and report it like this :-

0:000> dds 00D36AAC
00d36aac 6f6b798a gdiplus!GdipCreateSolidFill+0xcabac
00d36ab0 6f5fff97 gdiplus!GdipCreateSolidFill+0x131b9
00d36ab4 6f5ea816 gdiplus!GdipCreatePen1+0xcf
00d36ab8 004158ed*** WARNING: Unable to verify checksum for MyProj.exe
        [c:\vc7\vc7\platformsdk\include\prerelease\gdipluspen.h @ 33]
00d36abc 00415685 MyProj!CChildView::OnPaint+0xb5 
        [c:\projects\collage\docs\article\myproj\childview.cpp @ 50]
00d36ac0 7c1feedf MFC70D!CWnd::OnWndMsg+0x796 
        [f:\vs70builds\9466\vc\mfcatl\ship\atlmfc\src\mfc\wincore.cpp @ 2015]
00d36ac4 7c1fe71f MFC70D!CWnd::WindowProc+0x2e 
        [f:\vs70builds\9466\vc\mfcatl\ship\atlmfc\src\mfc\wincore.cpp @ 1737]
00d36ac8 7c1fc11a MFC70D!AfxCallWndProc+0xe0 
        [f:\vs70builds\9466\vc\mfcatl\ship\atlmfc\src\mfc\wincore.cpp @ 241]

As you can see by the highlighted code above, this leak took place at line 50 of ChildView.cpp.  You should now fix that leak and repeat the process again, until all leaks are removed.


2003-Mar-12 - Created


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

No Biography provided

You may also be interested in...

Comments and Discussions

Question+5 Pin
Mast Avalons24-Feb-12 9:23
memberMast Avalons24-Feb-12 9:23 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey18-Feb-12 4:26
professionalManoj Kumar Choubey18-Feb-12 4:26 
QuestionAlternate source for checked version of GDIPlus.dll? Pin
Member 18395314-Apr-03 7:47
memberMember 18395314-Apr-03 7:47 
AnswerRe: Alternate source for checked version of GDIPlus.dll? Pin
mmondry14-Apr-03 8:17
membermmondry14-Apr-03 8:17 
GeneralRe: Alternate source for checked version of GDIPlus.dll? Pin
Swinefeaster7-Sep-03 15:51
memberSwinefeaster7-Sep-03 15:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190114.1 | Last Updated 1 Apr 2003
Article Copyright 2003 by Michael Mondry
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid