WMemoryProfiler is (to my knowledge) the the first free profiler that you can use inside integration tests to verify that your component does not leak memory. It is very simple to use. The following code does get all new objects after the Allocate method and stores them by type in a ILookup table to print out all newly allocated string objects.

/// <summary>
/// Show feature to not only get statisics out of a process but also the newly allocated instances since the last call to MarkCurrentObjects.
/// GetNewObjects does return the newly allocated objects as object array
/// </summary>
static void InstanceTracking()
{
  using (var dumper = new MemoryDumper(true,true))
  {
     dumper.MarkCurrentObjects();
     Allocate();
     ILookup<Type, object> newObjects = dumper.GetNewObjects()
                                              .ToLookup( x => x.GetType() );

     Console.WriteLine("New Strings:");
     foreach (var newStr in newObjects[typeof(string)] )
     {
       Console.WriteLine("Str: {0}", newStr);
     }
 }
}

This will give you

New Strings:
Str: String data:
Str: String data: 0
Str: String data: 1
Str: String data: 2
Str: String data: 3
Str: String data: 4
Str: String data: 5
Str: String data: 6
Str: String data: 7
Str: String data: 8

The only thing you need to remember is to start your application not under the debugger since this API does need to make use of Windbg under the hood to make this output happen. An interesting side note might be that what you have seen is a process that did start a debugger, attach it to itself and did control the debugger. Self debugging at its best. This functionality is also exposed via the CdbEng (pure Windbg) and MdbEng (managed debugger).

 

For a full feature list see the Documentation Tab.

 

Last edited Jun 23, 2012 at 7:22 AM by Alois, version 7