ANTS Memory Profiler 8

Using the snapshot API

You can use the API exposed by ANTS Memory Profiler to take snapshots from within your code. First, you need to edit your application's code to trigger the snapshot, then run the built application alongside ANTS Memory Profiler.

Take snapshots from your code to ensure that snapshots are taken precisely when you believe that a leak occurs, or if your application does not have an interface through which you can control it. The snapshot API lets you essentially automate the process of taking a snapshot.

If your application is a Silverlight browser application, you cannot use the snapshot API. (This is due to security restrictions in Silverlight.)

Editing your code to invoke the snapshot:

  1. Create a reference to RedGate.MemoryProfiler.Snapshot.dll (You can find a copy in %ProgramFiles%\Red Gate\ANTS Memory Profiler 8\)
  2. Call RedGate.MemoryProfiler.Snapshot.TakeSnapshot() whenever you want to take a snapshot. This method returns true on success and false on failure. To take a snapshot and give it a memorable name at the same time, provide a string argument to the TakeSnapshot method, for example: RedGate.MemoryProfiler.Snapshot.TakeSnapshot("Clicked button").

We recommend that you contain the TakeSnapshot() method within a try-catch statement. This is because TakeSnapshot() can raise exceptions, for example if it is called more than 5 times in 30 seconds.

Running your application

  1. Start ANTS Memory Profiler.
  2. Set up ANTS Memory Profiler to profile your application in the normal way.
  3. When you click Start profiling, your application starts.
  4. Snapshots are taken automatically at the trigger points you defined in your code. If required, you can still use the Take memory snapshot button to take snapshots manually as well.
  5. Click Stop profiling
  6. Profiling results are shown in ANTS Memory Profiler.

Didn't find what you were looking for?