Destructors vs. Finalizers

Moritz Maxeiner via Digitalmars-d digitalmars-d at puremagic.com
Wed Jul 26 11:33:58 PDT 2017


On Wednesday, 26 July 2017 at 17:38:28 UTC, Dgame wrote:
> I don't get it. The GC collects the objects which aren't in use 
> anymore. The order in which this is currently happening is not 
> specified. So, how are the destructors supposed to be called in 
> the right order? Manually? ARC?

After the split:
Destructors are only for deterministic end of object lifetime, so 
yes, they are to be called by any scheme (such as manual 
management via destroy and reference counting - which is likely 
also implemented as calling destroy) that is deterministic.
Finalizers are for nondeterministic schemes such as the GC.
The GC *never* calls destructors directly, only finalizers.
A finalizer might manually call a destructor, but a destructor 
may never call a finalizer.


More information about the Digitalmars-d mailing list