检查 .NET 3.5 中给定实例有多少引用

发布于 2024-10-09 19:37:52 字数 34 浏览 0 评论 0原文

是否可以检查 .NET 3.5 中给定实例有多少引用?

Is it possible to check how many references are held to a given instance in .NET 3.5?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

落在眉间の轻吻 2024-10-16 19:37:52

您不能在运行时执行此操作。

You cannot do this at runtime.

﹂绝世的画 2024-10-16 19:37:52

如果加载 SOS 扩展,则可以使用 WinDbg 调试器来完成此操作:

.loadby sos.dll mscorwks

您需要找到内存中对象的地址,最好使用 !dumpheap 命令来完成。有了对象地址,您就可以运行 !gcroot

来查找对对象的所有引用。

This can be done using the WinDbg debugger if you load the SOS extension:

.loadby sos.dll mscorwks

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.

零度° 2024-10-16 19:37:52

您无法在运行时通过 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

难理解 2024-10-16 19:37:52

在调试时,您可以使用 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

凶凌 2024-10-16 19:37:52

我喜欢 ANTS Memory Profiler 来完成此类任务。

I love ANTS Memory Profiler for those kind of tasks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文