ANTS Memory Profiler - 7.1

ANTS Memory Profiler

Using the snapshot API - ANTS Memory Profiler

You can use the API exposed by ANTS Memory Profiler 7.1 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.

Note that, if your application is a Silverlight 4 (or later) browser application, you cannot take snapshots from your code. (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 7\)
  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").

Note: 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 startprofilingbutton, your application starts.
  4. Snapshots are taken automatically at the trigger points you defined in your code. If required, you can still use the amp_takesnapshot_button button to take snapshots manually as well.
  5. Click amp_stopprofiling_button
  6. Profiling results are shown in ANTS Memory Profiler.

Was this article helpful?

Search support
Forums

ANTS Memory Profiler

all products