Reputation: 1088
Is it possible to access the managed heap in a .NET application and e.g. enumerate the objects that are currently allocated there?
I know there are various tools out there that allow you to do that, but I would rather do this myself from code so that I can use it in automated tests, like for checking if everything is disposed and cleaned up after closing a form.
Upvotes: 4
Views: 1285
Reputation: 28500
Now you can use the ClrMD Nuget package.
The Nuget package is actually called Microsoft.Diagnostics.Runtime
. It will allow you to view objects in the heap as well of other properties of the CLR runtime.
Upvotes: 1
Reputation: 180788
http://sourceforge.net/projects/profilesharp/ has a profiler with the source code available.
Upvotes: 2
Reputation: 707
Profilers (using the Profiling API) are 'external' components (not quite COM) in the sense that they get loaded by the CLR and has various options of getting called on any method enter/leave/tail call in the managed code (and lots of other stuff as well). They are written in unmanaged code.
AFAIK there is no way to get this info internally without calling out to a profiler/debugger that monitors the CLR. Also remember that you can not always get this kind of information as much of it only exists after your code has finished execution (many Dispose() calls, finalization and such).
Upvotes: 1
Reputation: 117230
The only way, besides using a profiler, is with WinDbg and with the SOS extension loaded.
IIRC, you call !EEHeap.
Upvotes: 1