George Duckett
George Duckett

Reputation: 32428

Determining where object allocations for objects on the heap occurred

Is there any tool such that it can get a heap dump from a running application and determine/group objects by where in source code they were created?

With no changes to source code and ideally something free.

Upvotes: 12

Views: 595

Answers (7)

Dhruv
Dhruv

Reputation: 61

The SOS Debugging Extension

How to use : http://msdn.microsoft.com/en-us/library/yy6d2sxs.aspx

Upvotes: 0

ILoveFortran
ILoveFortran

Reputation: 3509

You need a .NET memory profiler. These tools allow you to follow the object graphs on the garbage collected heap and can be very useful in identifying the sources of memory leaks. While they may not necessarily tell you the method where an object was created they will tell which instances of which classes are holding on to the objects and allow you to take differences of snap shots of the gc heap. They don't require modifications to source code. You may want to have a look at What Are Some Good .NET Profilers?

Upvotes: 1

Martin Konicek
Martin Konicek

Reputation: 40924

As others suggested memory profilers, Memprofiler is definitely the most advanced one (I've tried all existing .NET profilers). It has a 14 day trial.

Upvotes: 1

Brian Rasmussen
Brian Rasmussen

Reputation: 116401

The information is not available if you create a memory dump. In order to gather this, you have to monitor the process as it is running. You could launch the application via WinDbg and set breakpoints on all the constructors you're interested in (hopefully you don't want to look at each and every object).

If you create the breakpoint, so it dumps the stack you will have the point of creation for the object. However, keep in mind that the objects may move around during GC, which will make parring objects with stacks difficult (or even impossible in some cases).

Since your question is tagged with performance and profiling, I gather that you want to reduce memory allocations. Why not just look at the numbers of objects created (or possibly look at the largest objects created) by looking at the heap. Then go through the source code and figure out where such instances are created.

Upvotes: 3

DiVan
DiVan

Reputation: 381

Good old windbg + sos + pdb will make the dumping. As for the "where in source code they were created" part - is impossible without instrumentation or injection.

Upvotes: 0

Michael Edenfield
Michael Edenfield

Reputation: 28338

Our QA teams use http://www.jetbrains.com/profiler/ for this kind of thing here when we run into bottlenecks. I'm pretty sure it will give you a list of allocations by method call. I'll go install it and check :)

Upvotes: 0

codymanix
codymanix

Reputation: 29468

What about .NET Memory Profiler from ANTS for example. Maybe CLR Profiler.

Upvotes: 3

Related Questions