Detect unrealized class instances in a running process?

I have an IIS application that runs in w3wp.exe. I am not 100% sure if one of my classes is deleted and increases the amount of memory over time (just looking at the memory usage in the task manager is not so reliable).

Is there an easy way to take a memory dump (which is easy in Win2008, via the task manager), load it into WinDbg or Visual Studio and just ask: "How many instances of Foo.Bar are in this memory dump?"

I know that I could / should use Memory Profiler, but now I do not have this option, since this is a production system.

+4
source share
2 answers

Is there an easy way to take a memory dump (which is easy in Win2008, via the Task Manager), load it into WinDbg or Visual Studio and just ask: "How many instances of Foo.Bar are in this memory dump?

You can use Proc Dump to get a memory dump.

In WinDbg !dumpheap –stat you will get a selection by type

If you use !dumpheap -type Foo.Bar , you should only get classes starting with Foo.Bar

see SOS.dll (SOS debugging extension) for more information

+4
source

You can use the decorator class, which has a finalizer and a delete method, and warns you about a missed order. Therefore, if your class looks like this:

 public class CustomerTracker { public bool IsNew() {...} } 

Then define the interface and make it client code:

 public interface ICustomerTracker { public bool IsNew(); } 

Define a decorator and use it where you create any of these objects:

 public class CustomerTrackerMemDecorator : ICustomerTracker { ICustomrTracker tracker; CustomerTrackerMemDecorator (ICustomrTracker tracker) { this.tracker = tracker; } public bool IsNew() { return tracker.IsNew(); } ~CustomerTrackerMemDecorator { Debug.Assert("Missed dispose found!"); } public override Dispose() { tracker.Dispose(); GC.SupressFinalize(this); } } 

Then, wherever you are:

CustomerTracker tracker = new CustomerTracker ();

replace it with

ICustomerTracker tracker = new CustomerTrackerMemDecorator (new CustomerTracker ());

+1
source

All Articles