Why do finalizing classes require more than one garbage collection cycle?

This article says

If an object has a finalizer, it is not immediately deleted if the garbage collector decides that it no longer "lives". Instead, it becomes a special root type until .NET calls the finalizer method. This means that for these objects usually requires more than one garbage collection will be deleted from memory, as they will survive the time when they are considered unused.

My question is, why does the GC not call the finalizer when it detects that the object can no longer reference and assemble the object right away? why is it needed more than garbage collection?

+5
source share
3 answers

Two points are considered:

  • . , - . , , ( ). , GC , .

  • , - , ( ), ... , ?

+6

( GC), GC . , , . :

  • , ( )
  • , ( GC, , , ).

, , , , GC ( ).

IDisposable Dispose() ; , .

+3

.net, : , "" , , any, "" , , , , , . ; , "". , , Finalize() . , , "" GC.

0
source

All Articles