Previously we have written about profiling performance and profiling memory with ANTS Profiler. This time we’re going to present a short tip for using ANTS Profiler, explaining how ANTS Profiler lets you quickly reduce the number of objects that you are looking at.
A common problem with profiling the memory of a .NET application is that there are an awful lot of objects to look at. Searching through a large number of objects, just to find the ones that you are interested in, is both time consuming and frustrating. In ANTS Profiler you can quickly reduce the number of objects that you are looking at by a careful use of grouping, filtering and sorting.
Let us walk through the steps for one of my typical scenarios – comparing the differences between two snapshots.
Quite often I use the memory profiler to find out what new objects are created when I execute a certain action (e.g. click on a button). To do this, I take a snapshot of the memory before I perform the action, and then another snapshot after the action. The screenshot below shows "All objects" from the second snapshot.
To focus on new memory created I immediately filter using the Comparison column to only show "New" objects that have been created since the previous snapshot. This immediately reduces the number of objects displayed in the grid from thousands to hundreds.
My next step is usually to group the objects by their "Namespace". This allows me to focus on all the objects from a particular namespace. Shown below is a screenshot of the grouped results focusing on the
I can now see immediately that the action that I performed resulted in the creation of 10 new rectangle shapes.
System.Drawing namespace grouping reveals that I am creating a very large number of
SolidBrush objects. I might want to take some more time to find out whether I really need to be creating so many new Solid Brushes!
Obviously you can choose to filter or group on any of the columns that are available in the "All objects" grid. It may well prove useful to filter out all the objects that do not have a source file so that you can focus on the objects created by your code, or group by allocation method to see which methods are creating the most objects.
Try it out for yourself – download a fully-functional, free trial from Red Gate’s website.