Evaluation of 4 Memory Profilers.

Alex van Buitenen, Dec 2006.

When looking for a tool to track down .NET memory leaks I evaluated 4 memory profilers:

The first two were installed at my workplace, for the second two I temporarily installed an evaluation version.

The key functionality I was looking for is tracking down memory leaks.
I want to make a snapshot from the memory, run a part of a program and then take a snapshot again.
Then I should get an overview of all new objects in memory, see from where they are referenced, and what they are referencing to.

DevPartner memory analysis (in DevPartner Studio Professional Edition version 7.1)

DevPartner integrates with Visual Studio. You can use the DevPartner Toolbars. Describing them here goes beyond the scope of this document.
In DevPartner we can start and stop tracking memory.
The memory usage is displayed in a graph.
Pressing the trash can forces a garbage collection.

Figure 1. Memory Analysis Window.

Now "View Memory Leaks" can be pressed.
The 5 Objects and Methods that refer to the most leaked memory are displayed:

Figure 2. The 5 Objects and Methods that refer to the most leaked memory.

Note here that we do not per definition want to look at the 5 Objects and Methods that refer to the most leaked memory.
It could very well be that those objects are allocated appropriately to be long living, while there is a small memory allocation that should have been garbage collected.
Therefore, it would be better to see a list of all newly allocated objects between the start and stop of the memory tracking.

Clicking "Show Complete Details" for Objects that refer to the most leaked memory" gives:

Figure 3. Objects that refer to the most leaked memory.

We see a table containing the objects that refer to the most leaked memory.
The graph shows the object selected in the table, with it's referrers.
Unfortunately, we cannot click on the objects in the graph to browse there.
Therefore, we cannot directly browse back to the objects that refer to this object.
We can however zoom in on the object to see what it is referencing:

Figure 4. Zoomed in on Form1.

As you see, the graph can get quite crowded and refusing.

Navigating through all the objects, their references and their referees is NOT easy in the DevPartner Memory Profiler.

Rational Purify.

Rational Purify integrates with Visual Studio. You can use the Rational Purify Toolbars. Describing them here goes beyond the scope of this document.
Rational Purify allows you to take snapshots.
The memory usage is displayed in a graph.
Pressing the "Recycle" button forces a garbage collection.

Figure 5. The Memory Graph.

After taking the snapshots we get a window that contains a Call Graph.
The thicker the lines between the funtions, the more memory is used.

Figure 6. The Call Graph.

The next tab gives us the Function List View:

Figure 7. The Function List View.

The next tab gives us the Object List View:

Figure 8. The Object List View.

What we are really interested in, is the difference in memory between the two snapshots that we have taken.
After making a Diff (or Comparison data set)  we get a Call Graph again:

Figure 9. The Diff Call Graph View.

The next tab gives us the Function List View:

Figure 10. The Diff Function List View.

Now you will probably think: "Where is the Diff Object View?"
The documentation says: "Comparison data sets do not contain object data.".

An Object Diff between 2 snapshots is NOT possible in Rational Purify.

Scitech .NET Memory Profiler 2.6.

Scitech integrates with Visual Studio. You can use the Scitech Toolbars.
Running the program however, calls the debug version of your program (when you've selected that in Visual Studio) but it does NOT call the debugger.
Setting breakpoints has no effect.

After taking two snapshots the SciTech .NET Memory Profiler automatically creates the comparison between the two:

Figure 11. Comparison between two snapshots.

Note: The Comparison snapshot can be selected from a dropdown box. We could therefore compare to another snapshot, instead of just the previous one.

Here we've filtered the objects so that we only see the objects that were new between the two snapshots.
We can see that there is 1 new StringCollection and we can zoom in on it:

Figure 12. Zooming in on the StringCollection.

There is one instance of a StringCollection and we can zoom in further on it:

Figure 13. Further zooming in until we've reached the strings in the StringCollection.

Note here that we've selected the "References" tab to delve deeper and deeper in the object hierarchy.
The Root Path on the right side gets updated, so we can always see the hierarchy of the objects that created the object we are inspecting.
We can double click on those object to navigate to them too.
We can also select the "Referenced by" tab and move backwards through the hierarchy.
There also are "Forward" and "Back" buttons (not shown here) that enable us to move thru the hierarchy. This is very helpful while browsing back since there might be lots of objects pointing to the object we are inspecting. Instead of looking back and wondering where we came from, we can just push the "Back" button.

Navigating through all the objects, their references and their referees is very easy in the SciTech Memory Profiler.
 

The SciTech Profiler also shows a real-time graph of the memory:

Figure 14. The memory graph.

Further more, the Scitech memory profiler enables tracking the disposure of unmanaged code.

Red Gate Ants Profiler 2.7.

The Red Gate Ants profiler does not integrate with Visual Studio. However, they promised "basic Visual Studio integration" in version 3, which will be out in March/April 2007.
The ANTS Profiler allows you to take snapshots of the memory.
ANTS first shows you a summary containing the "Biggest live objects" and  the "Classes with most live instances".

Figure 15. The ANTS Summary.

By moving to the "All objects" tab and filtering the "Comparison" column we can see which objects are new in memory:

Figure 16. The Comparison between the snapshots.

Note: The comparison column is the comparison between the last and the previous snapshot. Comparing to a snapshot made earlier is not possible.

The Call Stack can be shown by clicking the "Call Stack" tab:

Figure 17. The Call Stack.

The next screenshot shows how we've delved deeper in the hierarchy:

Figure 18. Zooming in until we've reached the strings in the StringCollection.

What is eye-catching in this screenshot is the clear overview we have here. The object we are examining, it's referees and it's references are visible in one screen.
We even see here that one of the strings in our StringCollection was new compared to the last snapshot, and we see it's value in a glance.
The well organized screens make us see the important details at the glance of an eye.

We can double click on any object to move there.
There also are "Forward" and "Back" buttons (White arrow on green dot in toolbar) that enable us to move thru the hierarchy. This is very helpful while browsing back since there might be lots of objects pointing to the object we are inspecting. Instead of looking back and wondering where we came from, we can just push the "Back" button.
The navigation between objects is absolutely excellent in the RED Gate Memory Profiler.

Overview of the functionality.

  Developer Studio
integration
Object Diff between
two snapshots
Easy Navigation
between Objects
DevPartner Memory Profiler
Rational Purify Memory Profiler
SciTech Memory Profiler
Red Gate Ants Memory Profiler

Table 1. The weak and strong point of the Memory Profilers.

Fully functional
Partly functional
Not functional

Table 2. Legend.

Note: All Profilers support showing the source code that made the memory allocations. That functionality is not described here.

Conclusion.

Which one is the best?

The SciTech Memory Profiler and Red Gate Ants Profiler are the ones that provide the functionality that I needed.

In the Red Gate Ants Profiler the well organized screens  make us see the important details at the glance of an eye.
The ease of  navigation between the objects is absolutely perfect in the  Red Gate ANTS Profiler.
The Red Gate Ants Profiler is very basic in its functionality, but within that functionality, it is a superb program.

On the other hand, the SciTech Profiler has some more functionality than the Red Gate Ants Profiler (real-time memory graph, and tracking of disposure of unmanaged code).
To be able to make a final choice, one should really work with both programs for a while.