Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to track allocation/deallocation?

As far as I can tell, this is isn't possible, so I'm really just hoping for a left field undocumented allocation hook function.
I want a way to track allocations like in _CrtSetAllocHook, but for C#/.NET.
The only visibility to the garbage collector/allocation appears to be GC.CollectionCount.
Anyone have any other .NET memory mojo?

like image 719
Jurney Avatar asked Sep 08 '08 18:09

Jurney


2 Answers

The CLR has a 'profiling API' that hooks into pretty much everything - it is what the commercial .NET memory profiling products use, I believe. Here is an MSDN link to the top level of the documentation: .NET Framework General Reference: About the Profiling API

See this MSDN magazine article for an introduction to the memory piece: Inspect and Optimize Your Program's Memory Usage with the .NET Profiler API

like image 72
McKenzieG1 Avatar answered Nov 20 '22 05:11

McKenzieG1


I would just use Red Gate's ANTS Profiler. It will tell you a lot about what's going on in memory without you having to learn the profiling API yourself.

like image 39
Jonathan Allen Avatar answered Nov 20 '22 05:11

Jonathan Allen