Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 214
George Duckett Avatar asked Jun 21 '11 15:06

George Duckett


2 Answers

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

like image 51
codymanix Avatar answered Sep 24 '22 14:09

codymanix


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.

like image 41
Brian Rasmussen Avatar answered Sep 25 '22 14:09

Brian Rasmussen