nesne olacak değil olmak çöp toplanan - ama GC.ReRegisterForFinalize
çağrı sürece çöp toplama işlemi için uygun olduğu bir sonraki sefer, sonlandırıcı , yeniden aday olmayacak.
örnek kod:
using System;
class Test
{
static Test test;
private int count = 0;
~Test()
{
count++;
Console.WriteLine("Finalizer count: {0}", count);
if (count == 1)
{
GC.ReRegisterForFinalize(this);
}
test = this;
}
static void Main()
{
new Test();
Console.WriteLine("First collection...");
GC.Collect();
GC.WaitForPendingFinalizers();
Console.WriteLine("Second collection (nothing to collect)");
GC.Collect();
GC.WaitForPendingFinalizers();
Test.test = null;
Console.WriteLine("Third collection (cleared static variable)");
GC.Collect();
GC.WaitForPendingFinalizers();
Test.test = null;
Console.WriteLine("Fourth collection (no more finalization...)");
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
Çıktı:
First collection...
Finalizer count: 1
Second collection (nothing to collect)
Third collection (cleared static variable)
Finalizer count: 2
Fourth collection (no more finalization...)
NET GC Diriliş için bir arama yapın, siz mesela bulacaksınız [bu makale] (http://msdn.microsoft.com/en-us/magazine/bb985010.aspx) –