Thursday, November 11, 2010

LeakDiag - An Effective Memory Leak Analysis Tool

Tip                 :         How to analyze memory leak using LeakDiag and LDGrapher.

Details           :         LeakDiag is memory leak analysis tool that helps developers to diagnose memory leaks, fragmentation, and other memory-related issues in applications or services. LeakDiag intercepts calls to specified memory allocations and tracks the various call stacks. It reports on the memory that has been allocated but not yet freed. With correct debug symbols, even the line of code that requested the allocations can be seen.

How to run LeakDiag:
1.       Configure the public symbol path as well as your local symbol path using LeakDiag Option dialog.
2.       We can resolve the symbols when logging itself. In the case of large application, we can resolve symbols after the logging using  sdecode.exe.
3.       We need to select the Process and memory allocator from LeakDiag main window.
4.       Press the start button.
5.       Take snapshot of stacks by clicking the log button. This will collect all stack frames which have allocated the memory and are not freed up till then. We need to take as many snapshots as possible, more the snapshots it is easier to find out the leaking stacks.
6.       The logs will available in the location specified in the option dialog.
7.       We need to take multiple files and track each stack in these files one by one, if the totalsize of stack value goes on increasing or even if it is remaining constant for a long time, then we can take that stack as a doubtful stack and check if memory allocated by that particular stack is getting freed correctly. Repeat the above process till we reach the suspicious code portion.

LDGrapher:                 The memory analysis using XML is a time consuming task.  To solve this, we can use LDGrapher. This is a redistributable tool provided by Microsoft and is available on
We can provide the generated XML files as an input and this tool will give us the graphical representation of our stacks.

The screenshots of LeakDiag and LDGrapher are shown below.

Reference :

Posted By : Febil Chacko

No comments:

Post a Comment