Do all three generations in the .NET GC have a finalizer queue, or does Generation 2 only have it? I am assuming that only Generation 2 has a finalizer queue and f-reachable queue associated with it.
There is one queue. You can view it with SOS: http://blogs.msdn.com/b/tess/archive/2007/10/19/net-finalizer-memory-leak-debugging-with-sos-dll-in-visual-studio.aspx
This is difficult to explain, the actual CLR code is not a very good match with the descriptions you'll find in the .NET literature and it is quite convoluted. There is indeed one logical structure inside the CLR with the name "finalization_queue". However, it has internal structure that organizes the finalizable objects by generation.
There's a better way to show this. If your assumption is correct, there would be no way an object can be finalized after a gen#0 collection. Try it:
using System;
class Program {
static void Main(string[] args) {
var obj = new Test();
obj = null;
Console.WriteLine("before gen#0 collection");
GC.Collect(0);
GC.WaitForPendingFinalizers();
Console.WriteLine("after gen#0 collection");
Console.ReadLine();
}
}
class Test {
~Test() { Console.WriteLine("finalized"); }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With