How to write a proper class destructor?

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Thu Jan 25 12:01:24 PST 2007


Bradley Smith wrote:
> Jarrett Billingsley wrote:
>> I remember someone suggesting that 'scope' be a valid modifier for 
>> class instance variables, and it'd basically mean "when this class 
>> gets destroyed, destroy this other instance as well."  Like 
>> auto-deletion when you use a scope reference in a function:
> 
> Is scope a valid modifier for a data member?

No, that paragraph was about a suggestion that it *should* be :).

>> Another solution would be to change the behavior of the GC so that 
>> deletion on program end _is_ deterministic.  That is, it'd basically 
>> run a collection sweep, call finalizers on objects which don't have 
>> references to them, and keep doing that until nothing is left.  That 
>> way, references to other classes would always be valid in destructors, 
>> since the GC wouldn't collect those references until everything that 
>> points to them is destroyed.
> 
> Are you saying that a proper class destructor can't be written without 
> modifying the language?

I think he's saying that it can be fixed by modifying the GC (which 
isn't so much part of the language as it is of the standard library).


More information about the Digitalmars-d-learn mailing list