How can I see objects inside heap and stack in C # .Net

Is it possible to see the contents of the stack and heap after each line of execution. I want to see this because it will give a clear idea of ​​memory allocation and freeing in .Net. Via

If there is any document or link that will clear my doubts, please reply.

+6
source share
2 answers

SOS or PssCor is a good place to start, along the side of WinDbg .

Once you figure this out; connect WinDbg to your process, download the debugger extension. For instance:

.load C:\pathtoextensions\psscor4.dll 

After that, you can issue the !dumpheap or !dumpstack .

The conclusion of both of these commands is very crude. !dumpheap -stat will give you a "statistical" overview of your heap. Type, allocated number, and bytes for all distributions.

This is not a very easy task. It will take some time to get enough practice with WinDbg if you have not used it before.

What you can do is set a breakpoint on the method using !bpmd and use the commands mentioned above, then go on to use p and run the commands again.

I am sure that there are other commercial tools, such as ANTS Profiler or dotTrace , which can do the job, but I do not have much experience with any tool.

Once you get started, you can ask (new) more specific questions about SOS or Psscor.

+2
source

Stack

 var stackInfo = new StackTrace(); 

Heap? No, you will need to use a profiler, debugger or appropriate APIs. Not an easy task. If you try this and encounter difficulties, it is better to ask a more specific question.

+3
source

Source: https://habr.com/ru/post/898016/


All Articles