is it possible to list all objects stored in heap. I would like to do something like this:
IEnumerable<GCHandle> listOfObjectsInHeap = GetListOfObjectsFromHeap();
The managed heapAfter the CLR initializes the garbage collector, it allocates a segment of memory to store and manage objects. This memory is called the managed heap, as opposed to a native heap in the operating system.
The garbage collector serves as an automatic memory manager. You do not need to know how to allocate and release memory or manage the lifetime of the objects that use that memory. An allocation is made any time you declare an object with a “new” keyword or a value type is boxed. Allocations are typically very fast.
Pinned objects are prohibited from moving within the heap. Typically, such objects are used by some unmanaged code or may be a result of using the fixed statement. Total size of all objects (excluding pinned objects) allocated in the heap segment.
Stack accesses local variables only while Heap allows you to access variables globally. Stack variables can't be resized whereas Heap variables can be resized. Stack memory is allocated in a contiguous block whereas Heap memory is allocated in any random order.
Using the ClrMD library you can connect to your own process and inspect the heap.
However, using ClrMD against a running process is known to limit the information available as the heap may be changing as you're trying to walk it.
http://blogs.msdn.com/b/dotnet/archive/2013/05/01/net-crash-dump-and-live-process-inspection.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With