Latest version: 4.3
Notes & articles
Identifying root objects with ANTS Profiler
This article explains how to use ANTS Profiler to find out why objects are surviving garbage collection. The techniques described in this article are useful when you have already identified the parts of the application that are causing memory leaks. For example, when you close a particular dialog box in your application, and you expect to see an immediate drop in memory usage, but what you actually see is the number of bytes on all the heaps remaining constant.
You can use tools such as Task Manager and Performance Monitor to identify the general area of your application where you suspect you have a memory leak. ANTS Profiler enables you to track down the actual object that is causing the memory leak.
Setting up the profiler
Start ANTS Profiler, and do the following:
- In the Profiler Project Wizard, select Memory profiler, and click Next.
- Select the type of application you want to profile.
- Specify the location of the executable file and click Finish.
ANTS Profiler asks you if want to start profiling your application. Click Yes.
To gather the profiling results, you will be taking a series of snapshots while your application is running. Click OK.
With the application running in ANTS Profiler, work through the application until you get to the part where you suspect you have a memory leak. Take a snapshot by clicking Take snapshot in the ANTS Profiler toolbar. Whenever you take a snapshot, ANTS Profiler displays the profiling results and leaves your application running, ready for you to take more snapshots.
Using the "All objects" panel
Now that you have your profiling results, you need to locate the object that is not releasing memory when you expect it to. Click the All objects tab to display the All objects panel. This panel shows all the live objects in your application at the time when you took the snapshot. As there are thousands of live objects in a .NET application, you will find it useful to group the objects by Namespace, so that you can concentrate on objects created by your own code, rather than the .NET Framework. You may also find it useful to group by Object type. This should make it easier to find the object that you want to investigate.
Identifying root objects
When your .NET application runs, it creates a hierarchy of objects that reference each other. For example, in a form with a toolbar, the toolbar contains buttons, and each button contains images or text.
When an object is no longer required, such as when a toolbar button is removed, the garbage collector can release memory, provided that the object is not referenced by any other object. To find potential memory leaks, you need to walk through the object references to find the object at the top of the hierarchy. The object at the top of a hierarchy is known as the root object. However, an object can belong to more than one hierarchy, so you may need to investigate all the hierarchies to find the actual source of your memory leak.
Click the object you are investigating in the All objects panel, and then click the Hierarchy tab. The grid on the left shows objects that reference the current object (Referenced from), and the grid on the right shows objects which the current object refers to.
You work your way up a hierarchy to identify root objects by clicking objects in the Referenced from grid. Each click takes you up a level in the hierarchy. When you get to the top of a hierarchy, the grid is empty. To be sure that you are at the top of a hierarchy, you can add the Root object column to the grid. To do this, right-click a column header in the Referenced from grid, and click Choose columns. In the Choose columns dialog box, drag the Root object column to the required position in the column header. When you reach the top of the hierarchy, Root object is set to Yes.
Fixing the problem
Having identified the root object, you can see the method that allocated the object by looking at the Allocated by value. Click the Source code tab to view the source code for the method. If there are many lines of code in your method, it may be useful to look for the new keyword to identify where the object is instantiated.
When you think you've found the source of your memory leak, fix the code in your application development tool, and then build your project. Run your application again in ANTS Profiler, and take a snapshot before you expect the object to be released, then another one after you expect the object to be released. When you examine the profiling results, the object should be present only in the results for the first snapshot. You may have to go through the process of identifying root objects and fixing your code several times, before your application uses an acceptable amount of memory.
Was this article helpful?
Thanks for your feedback!
- Enabling logs to track the profiling session
- Changing the interprocess communications ports in version 4
- Double hit counts occurring on one line
- System.EntryPointNotFoundException (Versions: 3,4 only)
- Version 3.0 Unhandled startup exception on Windows Vista
- Version 3 add-in grayed out on non-English Visual Studio 2005 and 2008
- Methods in (ASCX) web controls may not appear
- Failed to CoCreate Profiler error profiling a Windows service
- Multiple-core portable computers may show inflated times (version 3)
- No .NET methods were profiled on web application
- ANTS Profiler code instrumentation method
- Profiling a single assembly in version 3
- Filtering results by individual thread
- 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 an assembly in the Global Assembly Cache (GAC)
- Additional hidden statistics in the results grid (version 3)
- Multiple floating ANT icons in Visual Studio (version 3)
- ANTS Profiler overhead adjustments
- Profiling IIS web applications that need to run under the SYSTEM account
- Profiling a web application hosted in IIS on a fixed TCP port
- Add-in 'Object Reference not set to an instance of an object' error
- 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
- Abnormal termination caused by .NET 2.0 critical finalizer threads
- Cannot start COM+ application via Remote Desktop
- Fast mode and memory profiling options unavailable
- Finding the overall time taken to execute a thread
- Running an IIS application pool as a named identity
- IIS web application always loads default website
- 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
- Lines of source code do not align with hit count, time data in version 3
- Creating a global debugging symbols (PDB) directory
- Profiling a SharePoint site collection
- Using the add-in to profile solutions containing more than one project
- Methods may be missing on multi-core systems in version 3
- ASP .NET 1.x application recycling causing incomplete results
- Ambiguous site selection message when profiling IIS applications
- Application recycling causes incomplete results and other errors when profiling ASP .NET
- Profiling WCF services hosted in IIS
- Cannot profile IIS 6 web application on port lower than 1024
- (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
- Isolating single ASP .NET pages in ANTS Profiler results
- Missing hits for lines in the source code view
- ANTS Profiler restarts IIS
- Showing the amount of time taken for a method in one particular thread
- Common ASP .NET memory issues
- Please specify a valid URL message profiling ASP .NET
- Times on individual lines do not add up to method time
- Manually installing the add-in
- Error starting services running as "Local Service"
- Explanation of "thread blocked" methods in ANTS Profiler
- Call graph percentages do not add up exactly
- Operation could destabilize the runtime error profiling ASP .NET
- IIS ceases to work after profiling web applications
- Access to the Temp directory is denied error profiling web applications
- Problems with ANTS Visual Studio integration
- Unable to coCreate Profiler error profiling any application
- 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
- Getting help offline
- Finding memory leaks using ANTS Profiler
- Identifying root objects with ANTS Profiler
- Performance profiling with ANTS 4: tips for ANTS 3 users
- How to profile a desktop application that hosts the .NET runtime (ANTS Profiler 3)
- How to profile the performance of a single .NET assembly (ANTS Profiler 3)
- Profiling ASP.NET applications (ANTS Profiler 3)
- How to reduce the number of topics you see in the "All objects" panel (ANTS Profiler 3)
- ANTS Profiler release notes - version 4.xx
- Why can't ANTS Profiler find my source code? (ANTS Profiler 3)
- 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