我怎样才能看到堆内的对象? C#.Net 中的堆栈
是否可以在每行执行后看到堆栈和堆的内容。我想看到它,因为它将清楚地说明 .Net 中的内存分配和释放。 如果有
任何文件或链接可以消除我对您的答案的疑虑,请分享。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
SOS 或 PssCor 是一个不错的起点,沿着 WinDbg。
一旦你解决了这个问题;将 WinDbg 连接到您的进程,加载调试器扩展。例如:
之后,您可以发出
!dumpheap
或!dumpstack
命令。这两个命令的输出都非常原始。
!dumpheap -stat
将为您提供堆的“统计”概述。所有分配的类型、分配的数量以及总字节数。这不是一个超级简单的任务。如果您以前没有使用过 WinDbg,那么需要一段时间才能对它进行足够的练习。
您可以做的是使用
!bpmd
,并使用上面提到的命令,然后使用p
命令单步执行,然后重新-运行命令。我确信还有其他商业工具,例如 ANTS Profiler 或 dotTrace 可能会完成工作 - 但我没有太多经验任一工具。
开始后,您可以询问有关 SOS 或 Psscor 的(新)更具体问题。
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:
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 thep
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.
堆栈:
堆?不,您需要使用分析器、调试器或适当的 API。这不是一个简单的任务。如果您尝试后遇到困难,最好提出更具体的问题。
Stack:
Heap? Nope, you'd need to use a profiler, debugger, or appropriate APIs. Not a straightforward task. If you try it and have difficulties, best to ask a more specific question.
您还可以使用 dotnet-dump 工具检查堆:
You can also inspect the heap using the
dotnet-dump
tool: