How To Find Memory Leaks For Windows Applications

Managed code can have memory leaks. There is an open source tool called “CLR Profiled” for analyzing the behavior of your managed Application. It contains very good documentation about the different functions of the tool, however, I still find it bit hard to start with, so here is a simple step-by-step example of how to use it.

Step 1

Start the Profiler application
  • Navigate to CLRProfiler\Binaries\x86 (or x64) and run CLRProfiler.exe.

    CLR

Step 2

Attach Application to get Memory leakage related information.
  • Click Start Application and select your Application.
  • Now, your Application is running. You see that disabled buttons are enabled.

Step 3

Get memory leakage related information
  • Click Show Heal Now button.
  • You will see Heap Graph, as mentioned below.

    CLR

Heap Graph shows you all the objects in the Garbage collection heap, along with their connections. You can see all the objects, which are referenced by other objects and see all the way from the root object to your object, so you can understand exactly why your objects are still alive.

I found that ClrProfiler is easy to track leaks. It doesn’t have the fancy UI like other tools but it's free and helpful.