- First, you need the Debugging Tools for Windows installed.
- Open a command prompt and navigate to the debugging tools folder (usually C:\Program Files\Debugging Tools for Windows (x86).
- Type "gflags.exe /i yourApplication.exe
+ust" (without the quotes). This command creates a user mode stack trace database that will be used later. - Launch the application in WinDbg.
- Recreate the error and then break into the debugger.
- Run the command "!heap -s". This will display a summary of all of the current heaps. Find the one that seems to be bloated.
- Run the command "!heap -stat -h
" on the block that appears to be bloated. This will display statistics on the heap's allocations by allocation block size. My problem was that one resource type was being leaked so there was one block size that was used far more frequently than the others. Find that block size. - Run the command "!heap -flt s
". This will filter the heap to only show heaps of that particular size. - Now choose one of the UserPtr's in the list and run the command "!heap -p -a
" on it. This will display information on that particular block. It should also include a stack trace from when that memory was allocated. - Remember to remove the global flags by doing "gflags.exe /i
-ust" when you're done.
Monday, June 01, 2009
Heap Debugging (Memory/Resource Leak) with WinDbg
I recently had to do some heap debugging to solve an issue at work and it was a bit of a pain in the butt because there are several steps that I needed to take to set everything up. Here's what I had to do...
No comments:
Post a Comment