It’s hard for me to understand the difference between WaitForFullGCCompleteand WaitForPendingFinalizers + collect.
I already know that when a new object is created (which has a finalizer) - A link to this object is created in finalization queue.
Now - when a GC .collectmeets and discovers that the object must be assembled, the link from finalization queuemoves to f-reachable queue.
These links in the queue are treated as root. Now - a special thread wakes up from sleep in f-reachable queueand launches each object finalize.
Please note that this is done AFTER the phase collect. So only the next time we run GC.collect, the object will really disappear.
If we want to wait until the thread f-reachable queue'swill be made with all the means finalizewe have to call: WaitForPendingFinalizers.
And now, if we want to get the full collection, we need to run GC.collect again!
If so - it seems that a full GC can be done:
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true);
GC.WaitForPendingFinalizers();
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true);
So why should I GC.WaitForFullGCComplete()?
docs says:
Returns the status of a registered notification to determine whether it is a complete, blocking collection of garbage in a common language runtime completed.
Question
I do not understand: I already know when Gc completed, and it is at this point:
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true);
GC.WaitForPendingFinalizers();
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true);
So when should I use this method and not my code?
N.B.
(I saw what he uses here and here )
, - , , :
CLR # 4:
, WaitForFullGCApproach WaitForFullGCComplete , CLR .