How to write a proper class destructor?

Bradley Smith digitalmars-com at baysmith.com
Thu Jan 25 09:55:25 PST 2007


kris wrote:
> Bradley Smith wrote:
>> According to the documentation, a class destructor is "expected to 
>> release any resources held by the object."[1] However, if resources to 
>> be released are in objects to be garbage collected, "those references 
>> are no longer valid."[1]
>>
>> How is a class supposed to release something for which it no longer 
>> has a valid reference?
>>
>>
>>   Bradley
>>
>>
>>
>> [1] http://www.digitalmars.com/d/class.html#destructors.
> 
> Yeah, that's a good one :)
> 
> Tango has a good resolution for this, that stemmed from long discussion 
> on the NG. Those changes never made it into phobos, IIRC

Isn't the destructor behavior dictated by the language? How can it be 
fixed with a library? Replace or bypass the GC?


Thanks,
   Bradley


More information about the Digitalmars-d-learn mailing list