哪个线程正在使用给定的对象?

发布于 2024-12-18 15:26:06 字数 393 浏览 5 评论 0原文

  1. 我运行 dumpheap -type MyObjectType 命令来获取 MyObjectType 的方法表。它显示堆上的三个对象。
  2. 我运行 dumpheap -mt来获取地址。
  3. 我运行 !gcroot
    命令来查找对这些对象的引用,但什么也找不到
  4. !do
    并且它提供了有关该对象的字段等的详细信息。

如何找到哪个线程正在引用或使用对象?有什么命令可以找出来吗?

  1. I run dumpheap -type MyObjectType command to get the method table for MyObjectType. It shows three object on heap.
  2. I run dumpheap -mt <method table address> to get address.
  3. I run !gcroot <address> command to find the references to these objects, find nothing
  4. !do <address> and it provides details about fields for this object etc.

How can I find which thread is referencing or using object? Any command to find that out?

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

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

发布评论

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

评论(2

梦里南柯 2024-12-25 15:26:06

没有简单的方法可以做到这一点,但您可以为每个线程运行 !dso (即 ~*!dso)。这将告诉您每个线程引用哪些对象。为了帮助导航输出,我通常将其记录到文件中并使用 grep 或合适的文本编辑器来搜索结果。

There's no easy way to do this, but you could run !dso for each thread (i.e. ~*!dso). That will tell you which objects each of the threads reference. To help navigate the output I usually log it to a file and use grep or a decent text editor to search the results.

风透绣罗衣 2024-12-25 15:26:06

您可以尝试使用 Microsoft 的 CLR Profiler 来找出哪个线程分配并访问您的对象。我不确定 !gcroot 是否显示等待终结器的对象,但 CLR Profiler 肯定会显示。您的对象也可能根本没有从任何 GC 根引用,它只是等待收集发生。这可能需要相当长的时间,特别是如果它分配在 LOB 堆中。尝试强制执行几次 GC(并查看 gen0-2 回收是否确实发生)并查看您的对象是否存活。

You might try to use Microsoft's CLR Profiler to find out which thread allocated and accessed your object. I'm not sure if !gcroot shows objects waiting for finalizer, but CLR Profiler definitely does. Your object also might be not referenced from any GC root at all and it's just waiting for collection to occur. It can take quite some time especially if it is allocated in LOB heap. Try forcing a few GCs (and see if gen0-2 collections actually took place) and see if your object survives.

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