ANTS Memory Profiler 7

Attaching to a process

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):

  1. Create a new file, and copy the following XML into it:

    <configuration>
       <runtime>
          <gcConcurrent enabled="false"/>
       </runtime>
    </configuration>
  2. 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.
  3. 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):

  1. Open the WebDev.WebServer.exe.config file, located at %ProgramFiles%/Common Files/microsoft shared/Dev Server/, in a text editor or XML editor.
  2. Under the <runtime> node, insert the following text:
    <gcConcurrent enabled="false"/>
  3. Save the WebDev config file.

When you have finished profiling, delete the <gcConcurrent> node.

Profiler settings

  1. Start ANTS Memory Profiler. If it is already running, on the File menu, click New Profiling Session...
  2. On the ANTS Memory Profiler Settings dialog box, on the Application Settings tab, select Attach to a .NET 4 process.
  3. 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  .
  4. Select the process that you want to profile.
  5. If required, change the performance counters to record.
  6. Click .
  7. Check whether there are any memory problems.

If you experience problems, see Attach to process unavailable with some anti-virus software.


Didn't find what you were looking for?