ANTS Memory Profiler - 7.1
5. Finding and fixing a memory leak - ANTS Memory Profiler
Before you look for a memory leak, 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 about the .NET heaps before you start.
Your approach to finding the source of the leak will depend on whether you have a hypothesis as to what is causing the problem.
If you think you know what is causing the problem
You may already have an idea of the action that might be causing the problem. In this case, use ANTS Memory Profiler to avoid time-consuming trial-and-error investigations in the code.
- Start ANTS Memory Profiler and start profiling your application.
- Use your application until the point where you are interested in its memory.
- Click
. - Cause the action or method to take place (for example, open the dialog box).
- Click
. - Switch to the Class List and try each of the following approaches to check whether the type that you suspect is the source of the problem:
- Type the name of the type which you suspect is causing the problem into the search box.
- On the filter panel, click Filter by Reference. Select Kept in memory exclusively by, click Add class/interface, and enter the name of the type there.
- If you know that the class should only be in memory because it is referenced only by one other class, check using the Never referenced by filter.
- If this procedure does not reveal any problems, continue reading 'Analyzing heap usage', below.
If you do not know what could be causing the problem
- Set up ANTS Memory Profiler
- Click
. - When you see the Bytes in all heaps graph on the timeline increase substantially, click
twice, a few seconds apart. - Continue reading at 'Analyzing heap usage' below.
Analyzing heap usage
Our best advice for analyzing heap usage is to ensure that you perform the analysis methodically, noting the results so that you can check that any changes made to your code have fixed the problem.
For each suspicious class (see the list below), in turn:
- Show the Instance Categorizer graph.
- If the class is one of yours, switch to the All references mode, so you can see the objects this class references.
- Check how the class is being kept in memory by looking at classes displayed to the left of your selected class. Check especially for any event handlers referencing your selected class.
- If a path looks incorrect, switch to the Instance Retention Graph to show how an instance is referenced along that path.
Suspicious classes are:
- The largest classes (see the Summary or Class List)
- Classes displayed when the Kept in memory exclusively by disposed objects / by event handlers filters are applied. Having objects in the latter is an especially good indicator of a leak (or poor coding practice).
- Classes which ought not to be displayed when the Survivors in growing classes and/or New objects filters are applied.
Tip: For the largest classes, you can jump straight to the categorized references graph from the summary. You do not need to generate the Class List every time.
Solving the memory leak
Once you have identified a path which is incorrect:
- Break the incorrect references in your code
- Retest the leak.
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