ANTS Memory Profiler - 7.1
4. Finding out what is using most memory - ANTS Memory Profiler
This topic describes how to find the classes that are using the most memory in your application.
Before finding out what is using most memory, we recommend that you first check for large object heap fragmentation and use of unmanaged memory.
If you are not familiar with memory profiling, you might find it helpful to read the .NET Memory Primer before you start.
Tip: You should not normally filter classes that you do not recognize. For example, if your code contains an array which itself contains a large number of byte arrays, you should start by looking at those byte arrays.
- Start ANTS Memory Profiler and start profiling your application.
- Use your application until the point where you are interested in its memory. For example, if you believe that a lot of memory is used when a certain screen is displayed, use the application normally until the screen is shown.
- Click
. - On the Summary, look at Largest classes. The largest classes are shown in order of the amount of memory they use.

- Starting with the largest class, click each class in turn to see the instance categorizer for that class. For this analysis, you are exploring memory usage by following references to a class, so it is not important if you do not recognize these classes.
- Instances of the chosen class are grouped by the chain of references which holds them in memory, with the largest group of instances displayed at the top of the screen. Starting with the largest category, use the explorer to look at what is keeping your selected class in memory, reading the graph from right-to-left.
For example, System.String is often the largest class; using the instance categorizer you can find out what is keeping strings in memory, such as an event handler.
- If the largest class does not reveal interesting results, click Summary, and try again with the next-largest class, and so on.
- If you still cannot see why large amounts of memory are being used after you have examined all of the largest classes by size, click Other classes. The Class List is displayed. Sort the Class List by Live Instances, and look at the instance categorizer for the classes with the most instances.
After using the instance categorizer to find out why instances of a class are still in memory, you might find that some instances are being kept in memory by a type (most commonly an event handler) that should not be referencing those objects. If this happens, when viewing the instance categorizer:
- Click Show instances on this path.
- The Instance List is displayed, showing the instances of the object which are retained on the path previously shown in the instance categorizer.
- Click on any instance to select it (it doesn't matter which one, because they are all on the same shortest path) then click
to display the instance retention graph. - Look for the reference that should not be there on the instance retention graph, which shows all paths holding the object in memory.
- Change your code to remove the incorrect reference, and then check that the problem is fixed.
Worked example
In this worked example, ANTS Memory Profiler is used to find out what uses most memory in Red Gate's Exception Hunter:
- The
Byte[]class is the largest class, accounting for 73.74MB of managed memory used by the application.
- Click Byte[].
- The Instance Categorizer shows that most instances of Byte[] (totaling 23.9MB) are held on a path where the shortest route to a GC root object leads to an object called
cB. On theByte[]node on this path, click Show instances on this path.
- The Instance List lists the 46 objects on this path. For instances of
System.Stringit might be interesting to use the Instance List to look at the values of the strings, but this is unlikely to be the case for Byte[] instances, so choose any one and click
.(All of the instances in the Instance List are all on the same shortest path, so it should make little difference which one you choose. Selecting the instance with the greatest size with children is often a sensible start, however.)

- The Instance Retention Graph shows which other types keep this instance in memory.

Conclusions:
- The
Byte[]class accounts for most memory used by this program (73.74MB). - The largest number of objects from the
Byte[]class (46 instances, totaling 23.9MB) are held on a path leading back to a GC root object from the classcB. - The selected instance is being kept in memory by
cv, which in turn is being kept in memory by bothcBandcB+e. - You now need to decide whether this should be the case, or whether there is a problem.
Was this article helpful?
ANTS Memory Profiler
- Installation error 5100 when installing ANTS Performance Profiler and ANTS Memory Profiler
- Attach to process unavailable with some anti-virus software
- Fragmentation notices in ANTS Memory Profiler 7
- The snapshot failed because .NET did not report every referenced object... manually switch your application to the workstation garbage collector.
- Profiling Sharepoint 2010
- Upgrading to ANTS Memory Profiler 7
- Memory leaks observed when profiling Windows Presentation Framework (WPF) applications
- Windows service profiling fails if the service uses a system account
- Log files
- The type initializer for 'y.layout.hierarchic.ClassicLayerSequencer' threw an exception
- Forcing your application to use .NET 4
- System.EntryPointNotFoundException (Versions: 3,4 only)
- Failed to CoCreate Profiler error profiling a Windows service
- ANTS Profiler code instrumentation method
- Add-in fails to load when using RunAs to start Visual Studio as another user
- Profiling unit tests using Nunit
- Can I profile Compact Framework applications?
- Profiling a SharePoint 2007 Web Part
- Profiling IIS web applications that need to run under the SYSTEM account
- Profiling a web application hosted in IIS on a fixed TCP port
- Profiling client-side XBAP .NET applications
- ANTS Profiler prompts for location of source code which is not your own source code
- ANTS menu remains in Visual Studio after uninstall of ANTS Profiler
- Profiling a web application needing to run as the Network Service account
- Cannot start COM+ application via Remote Desktop
- Profiling BizTalk applications
- Profiling Microsoft Office managed-code add-ins
- The system cannot find the file specified
- Error Stopping IISAdmin profiling IIS web application on Windows XP
- ANTS Memory Profiler total size of all objects does not match the memory footprint of an application
- Creating a global debugging symbols (PDB) directory
- Using the add-in to profile solutions containing more than one project
- Application recycling causes incomplete results and other errors when profiling ASP .NET
- (version 5) Support for profiling Silverlight applications
- Couldn't open metabase error when profiling ASP .NET hosted in IIS
- Failed to coCreate Profiler on ASP .NET web application
- HTTP error 404.17 profiling ASP .NET 1.1 on IIS 7
- Performance counters missing from results
- ANTS Profiler restarts IIS
- Please specify a valid URL message profiling ASP .NET
- Operation could destabilize the runtime error profiling ASP .NET
- IIS ceases to work after profiling web applications
- ANTS Profiler has been split into two distinct programs
- Problems with ANTS Memory Profiler 5 and multiple AppDomains
- System.ArgumentOutOfRangeException or CouldNotMapFileException errors in Memory Profiler 5
- Windows Installer errors 1603 and 2738 occurring during installation
- Unable to coCreate Profiler error profiling any application
- General information about "Private Bytes"
- Profiler stopping while profiling an in-browser Silverlight application
- Error: 'Could not load file or assembly vjslib'
- "No Disk" error occurring while profiling application
- Silverlight out-of-browser profiling stops with no results
- Memory Profiler failing to profile web applications with "unable to connect to server"
all products
- Some Red Gate products identified as containing a trojan by Anti-Virus software
- Activation may fail with Unknown Error -1
- Product uses web help although a CHM file is available locally
- Argument exception resulting from missing environment variable
- Check for updates may fail when used through proxies
- 'Unidentified Publisher' error when repairing or uninstalling
- Licensing activates product as standard edition
- Moving Red Gate software products to another machine
- Red Gate tools log locations
- The application UI opening slowly when there is no internet access
ANTS Memory Profiler
- Activating your products
- Activating your products
- ANTS Memory Profiler release notes - version 6.xx
- ANTS Memory Profiler release notes - version 7.xx
all products
- Red Gate product acknowledgements
- Activating your products
- Activating your products
- Red Gate bundle history
- Check for updates
- Troubleshooting Check for Updates errors
- Current versions
- Deactivating your products
- Installing Red Gate products from the .msi file
- Requesting additional activations
- Serial numbers for bundles
- Reactivating using a different serial number
- Extending your trial
- Finding your serial numbers
- Moving a serial number from one computer to another
- No response received for manual activation
- Licensing and activation resources
- Licensing and activation resources
- Troubleshooting licensing and activation errors
- Licensing and activation FAQs
- Red Gate tools log file locations
- Download old versions of products
- Download product prerequisites & utilities
- Support & upgrades
- Upgrading your software
- Upgrading FAQs

Understanding memory problems