c# – 如何在GC完成列表中列出所有对象?
作者:互联网
我的程序崩溃,它是VS的可视化工具,因此,调试它非常困难,我试图进行转储并使用WinDbg来研究它,但它不成功.
所以,现在我尝试以编程方式将手放在该列表上,但我不知道如何.谢谢.
解决方法:
我不认为有办法通过.NET的托管框架类库(FCL)进入终结队列.我怀疑如果你想以编程方式而不是debugging with WinDbg这样做,你(就像WinDbg和类似的工具)将需要使用CLR的非托管调试&为此目的分析API.
看看ICORDebugGCReferenceEnum
COM interface.您可以通过ICorDebugProcess5::EnumerateGCReferences
检索该类型的对象:
“Provides an enumerator for objects that will be garbage-collected.”
“The 07003 objects in the collection populated by [the 07004] 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.)
枚举器返回的每个对象都有一个字段类型.您可能希望过滤该字段与值CorGCReferenceType.CorReferenceFinalizer
匹配的对象.
标签:c,garbage-collection,finalization 来源: https://codeday.me/bug/20190609/1204709.html