Attaching to a process
Published 17 December 2012
If your application is not a .NET 4 application
Due to a limitation in previous versions of the CLR, you can only attach ANTS Memory Profiler to a .NET 4 process.
If your process runs on an older version of .NET, however, it is often possible to force it to run as .NET 4 without recompiling it. For more information, see Forcing your application to use .NET 4.
Before you start
Before you can attach ANTS Memory Profiler to a running .NET 4 process, you must first disable concurrent garbage collection in your application. This allows ANTS Memory Profiler to monitor garbage collections, which it cannot do if garbage collections take place in a different thread.
Disabling concurrent garbage collection means that garbage collection will take place in the same thread as the application's thread. Note: This may affect the performance of your application; see the notes below.
For more information on concurrent garbage collection, see Fundamentals of garbage collection: concurrent garbage collection (MSDN).
To disable concurrent garbage collection, follow the steps below:
- While concurrent garbage collections are disabled, your application will run faster but may pause occasionally to allow garbage collections to take place.
- While concurrent garbage collections are disabled, the total memory footprint of your application is fractionally increased. This is because the concurrent garbage collector would normally build a graph of unreachable objects on the other thread. This difference should not be significant enough to alter the results shown by ANTS Memory Profiler.
- You cannot attach to a .NET 4 process which is running in server garbage collection mode. If your configuration file contains
<
gcServer enabled="true"/>
, delete this node.
Disabling concurrent garbage collection (If you are not attaching to a webservice running on the web development server):
Create a new file, and copy the following XML into it:
<configuration> <runtime> <gcConcurrent enabled="false"/> </runtime> </configuration>
- Save this file in the same directory as the application's executable file with the same name as the executable file, but appending a .config extension. (For example, if your application is sample.exe, the configuration file must be named sample.exe.config).
It is not necessary to rebuild your executable. The .NET CLR will automatically load the configuration file at runtime. - Run your executable and then attach ANTS Memory Profiler to it (see Profiler settings).
When you have finished profiling, delete the configuration file.
Disabling concurrent garbage collection (If you are attaching to a webservice running on the web development server):
- Open the WebDev.WebServer.exe.config file, located at %ProgramFiles%/Common Files/microsoft shared/Dev Server/, in a text editor or XML editor.
- Under the
<runtime>
node, insert the following text:<
gcConcurrent enabled="false"/>
- Save the WebDev config file.
When you have finished profiling, delete the <
gcConcurrent>
node.
Profiler settings
- Start ANTS Memory Profiler. If it is already running, on the File menu, click New Profiling Session...
- On the ANTS Memory Profiler Settings dialog box, on the Application Settings tab, select Attach to a .NET 4 process.
- Processes running under the same user profile as ANTS Memory Profiler are shown in a list. Processes which are not .NET 4 processes are unavailable. To show processes from other users select Show processes from all users. To refresh the list, click .
- Select the process that you want to profile.
- If required, change the performance counters to record.
- Click .
- Check whether there are any memory problems.
If you experience problems, see Attach to process unavailable with some anti-virus software.