Is it possible to see contents of stack and heap after every line of execution. I want to see it as it will give clear idea about memory allocation and deallocation in .Net. With your
If any document or link which will clear my doubts with your answer please share.
Go to Debug-> Windows-> Diagnostics Tools. The Snapshot gives shows a list view of all the managed objects on the heap.
The easy way to monitor Heap usage is by using a commercial APM (Application Performance management tool) such as CA Wily APM, AppDynamics, New Relic, Riverbed, etc. APM tools not only monitor the heap usage, but you can also configure the tool to Alert you when Heap usage is not normal.
If you have a heap dump file saved on your local system, you can open the file in Java VisualVM by choosing File > Load from the main menu. Java VisualVM can open heap dumps saved in the . hprof file format. When you open a saved heap dump, the heap dump opens as a tab in the main window.
Whenever an object is created, it's always stored in the Heap space and stack memory contains the reference to it. Stack memory only contains local primitive variables and reference variables to objects in heap space.
SOS or PssCor are a good place to start, along side WinDbg.
Once you've got that sorted out; attach WinDbg to your process, the load the debugger extension. For example:
.load C:\pathtoextensions\psscor4.dll
After that, you can issue the !dumpheap
or !dumpstack
commands.
The output of both of these commands is very raw. !dumpheap -stat
will give you a "statistical" overview of your heap. The type, the number allocated, and the bytes in total for all allocations.
This isn't a super straightforward task. It'll take a while to get enough practice with WinDbg if you haven't used it before.
What you can do is set a breakpoint on a method using !bpmd
, and use the commands mentioned above, then step over using the p
command, and re-run the commands.
I'm sure there are other commercial tools like ANTS Profiler or dotTrace that may get the job done - but I don't have a lot of experience with either tool.
Once you've gotten started, you can ask (new) more specific questions about SOS or Psscor.
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