我有一个对象,它会一直存在。在使用完后,我正在删除所有我能看到的与它相关的引用,但它仍然没有被回收。它的生命周期非常复杂,所以我无法确定是否已清除所有引用。
if ( container.Controls.Count > 0 )
{
var controls = new Control[ container.Controls.Count ];
container.Controls.CopyTo( controls, 0 );
foreach ( var control in controls )
{
container.Controls.Remove( control );
control.Dispose();
}
controls = null;
}
GC.Collect();
GC.Collect(1);
GC.Collect(2);
GC.Collect(3);
如何查找一个对象还有哪些引用?为什么它没有被垃圾收集器回收?
} controls = null; } GC.Collect(); GC.Collect(1); GC.Collect(2); GC.Collect(3); 但它仍然在内存中。这意味着它仍然有根源。我该如何找到这些根源? - er-v
} controls = null; }GC.Collect(); GC.Collect(1); GC.Collect(2); GC.Collect(3); `但它仍然在内存中。这意味着它仍然有根源。我该如何找到这些根源? - er-v