destructors and GC again

Sean Kelly sean at f4.ca
Mon Oct 16 09:09:36 PDT 2006


Lutger wrote:
> Sorry for this topic again, I'm still not exactly sure: when an 
> unreferenced object is collected during the lifetime of your program 
> (before main exits), is the destructor of this object guaranteed to be 
> called? I expect it to be so, as otherwise destructors seem pretty 
> useless (and dangerous), but cannot infer this from the spec.

When an object is collected by the GC, it's dtor will be called. 
However, the GC may not detect an orphaned object as collectable if 
there is a value in memory somewhere that "looks" like a reference to 
that object.


Sean



More information about the Digitalmars-d-learn mailing list