Windows - Memory Leak Analysis using Windbg

Windbg is a tool from the house of MS. It come handy when debugging in a production enviornment as it is light weight. I have been using Windbg for the last few weeks and I would like to share some tips.

Let us start of with memory leak analysis!

Download Location: Debugging Tools For Windows


Windbg has build in extension exts.dll which can used to find memory leaks. Here are the steps. Enable Stack backtrace from your executable using gflags.exe +ust /i . gflags.exe comes along with the Debugging Tools For Windows.

1. Start your program and start leaking your application
2. Run WinDBG and attach to the your process. (windbg.exe -pn ).
3. From the WinDBG command line do a !heap -stat, this will list down all the active heap blocks
4. Then do a !heap -stat -h for the block with Maximum Committed + Virtual Allocation Bytes, this will list down the handle specific allocation.
5. Now do a !heap -flt s for the size which is being allocated that we got from previous output, it will list down all the specific blocks with that particular size.
6. Then do a !heap -p -a < address >, address is the User Addr then you will get the stack trace; from where you have allocated that much bytes.

Good luck guys!!
Let your RAM Rest In Peace.