如何列出 GC finalization 列表中的所有对象?
How to list all object in GC finalization list?
我的程序崩溃了,它是VS的可视化工具,所以很难调试,我试过制作转储并使用WinDbg研究它,但没有成功。
所以,现在我尝试以编程方式处理该列表,但我不知道如何操作。谢谢。
我认为没有办法通过 .NET 的托管框架 Class 库 (FCL) 进入完成队列。我怀疑如果你想编程而不是,你(就像WinDbg和类似工具)将需要使用CLR的非托管调试和分析API来实现结束。
看看ICORDebugGCReferenceEnum
COM interface. You can retrieve on object of that type via ICorDebugProcess5::EnumerateGCReferences
:
"Provides an enumerator for objects that will be garbage-collected."
"The COR_GC_REFERENCE
objects in the collection populated by [the ICorDebugGCReferenceEnum::Next
method] represent three kinds of objects:
Objects from all managed stacks. This includes live references in managed code as well as objects created by the common language runtime.
Objects from the handle table. This includes strong references (HNDTYPE_STRONG
and HNDTYPE_REFCOUNT
) and static variables in a module.
Objects from the finalizer queue. The finalizer queue roots objects until the finalizer has run."
(Hyperlinks and emphasis added by me.)
枚举器返回的每个对象都有一个字段type
。您可能想要过滤该字段与值 CorGCReferenceType.CorReferenceFinalizer
.
匹配的对象
如果您想查看一个对象是否在终结队列或 f-reachable 队列中,当您启动 WinDBG 时,首先使用 dumpheap -stat
或任何其他命令找到您的对象。找到对象地址后,可以使用 !FinalizeQueue
输出每一代有多少对象 finalizable,以及有多少对象 ready定稿。前者是finalization队列,后者是f-reachable队列。
例如:
0:003> !FinalizeQueue
SyncBlocks to be cleaned up: 0 MTA Interfaces
to be released: 0 STA Interfaces to be released:0
generation 0 has 370 finalizable objects
(0000000000d29030->0000000000d29bc0)
generation 1 has 4 finalizable objects
(0000000000d29010->0000000000d29030)
generation 2 has 8 finalizable objects
(0000000000d28fd0->0000000000d29010)
Ready for finalization 571 objects
(0000000000d29bc0->0000000000d2ad98)
现在,您可以看到您的对象地址 space 所在的位置。
很棒的教程是 available here
我的程序崩溃了,它是VS的可视化工具,所以很难调试,我试过制作转储并使用WinDbg研究它,但没有成功。
所以,现在我尝试以编程方式处理该列表,但我不知道如何操作。谢谢。
我认为没有办法通过 .NET 的托管框架 Class 库 (FCL) 进入完成队列。我怀疑如果你想编程而不是
看看ICORDebugGCReferenceEnum
COM interface. You can retrieve on object of that type via ICorDebugProcess5::EnumerateGCReferences
:
"Provides an enumerator for objects that will be garbage-collected."
"The
COR_GC_REFERENCE
objects in the collection populated by [theICorDebugGCReferenceEnum::Next
method] represent three kinds of objects:
Objects from all managed stacks. This includes live references in managed code as well as objects created by the common language runtime.
Objects from the handle table. This includes strong references (
HNDTYPE_STRONG
andHNDTYPE_REFCOUNT
) and static variables in a module.Objects from the finalizer queue. The finalizer queue roots objects until the finalizer has run."
(Hyperlinks and emphasis added by me.)
枚举器返回的每个对象都有一个字段type
。您可能想要过滤该字段与值 CorGCReferenceType.CorReferenceFinalizer
.
如果您想查看一个对象是否在终结队列或 f-reachable 队列中,当您启动 WinDBG 时,首先使用 dumpheap -stat
或任何其他命令找到您的对象。找到对象地址后,可以使用 !FinalizeQueue
输出每一代有多少对象 finalizable,以及有多少对象 ready定稿。前者是finalization队列,后者是f-reachable队列。
例如:
0:003> !FinalizeQueue
SyncBlocks to be cleaned up: 0 MTA Interfaces to be released: 0 STA Interfaces to be released:0
generation 0 has 370 finalizable objects
(0000000000d29030->0000000000d29bc0)generation 1 has 4 finalizable objects
(0000000000d29010->0000000000d29030)generation 2 has 8 finalizable objects
(0000000000d28fd0->0000000000d29010)Ready for finalization 571 objects
(0000000000d29bc0->0000000000d2ad98)
现在,您可以看到您的对象地址 space 所在的位置。
很棒的教程是 available here