检查 .NET 3.5 中给定实例有多少引用
是否可以检查 .NET 3.5 中给定实例有多少引用?
Is it possible to check how many references are held to a given instance in .NET 3.5?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您不能在运行时执行此操作。
You cannot do this at runtime.
如果加载 SOS 扩展,则可以使用 WinDbg 调试器来完成此操作:
您需要找到内存中对象的地址,最好使用
!dumpheap
命令来完成。有了对象地址,您就可以运行!gcroot
来查找对对象的所有引用。
This can be done using the WinDbg debugger if you load the SOS extension:
You'll need to find the address of the object in memory, probably best done using the
!dumpheap
command. With the object address, you can then run!gcroot <address>
to find all the references to your object.您无法在运行时通过 CLR 获取此信息,因为 CLR 不维护引用计数。一个重要的暗示是垃圾收集器是分代的,而不是引用计数驱动的。
Raymond Chen 在此处发表了一篇关于此主题的好文章:
http: //blogs.msdn.com/b/oldnewthing/archive/2010/08/11/10048629.aspx
You can not get this information at runtime via the CLR as reference counts are not maintained by the CLR. A big hint of this is that the Garbage Collector is generational and not reference count driven.
Raymond Chen has a good post on this topic here:
http://blogs.msdn.com/b/oldnewthing/archive/2010/08/11/10048629.aspx
在调试时,您可以使用 Windbg 来获取此数据。 Windbg中有具体的命令。我不是 Windbg 专家,但这可以帮助您入门
http: //www.bytetalk.net/2009/03/windbg-tips-and-tricks.html
While debugging, You can use Windbg to get this data. There are specific commands in Windbg. I am not an expert in Windbg but this would get you started
http://www.bytetalk.net/2009/03/windbg-tips-and-tricks.html
我喜欢 ANTS Memory Profiler 来完成此类任务。
I love ANTS Memory Profiler for those kind of tasks.