开发者

How to list all managed objects in heap in .Net?

开发者 https://www.devze.com 2023-01-01 17:27 出处:网络
is it possible to list all objects stored in heap. I would like to do something like this: 开发者_JS百科IEnumerable<GCHandle> listOfObjectsInHeap = GetListOfObjectsFromHeap();

is it possible to list all objects stored in heap. I would like to do something like this:

开发者_JS百科IEnumerable<GCHandle> listOfObjectsInHeap = GetListOfObjectsFromHeap();


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


You can use the Profiling API to achieve this. Unfortunately not in managed code.


I am not aware of any managed function that allows you to do this. You could retrieve this information using the HeapWalk function. Here's an example of using it (it creates a new heap but you could retrieve the current process heap with GetProcessHeap).

0

精彩评论

暂无评论...
验证码 换一张
取 消