How to write a proper class destructor?
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Thu Jan 25 11:58:04 PST 2007
Bradley Smith wrote:
> 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?
>>>
>>>
>>> [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?
*Behavior* is dictated by the language, yes. But the *order* in which
they're invoked is determined by the library (specifically, the GC) and
the program (if 'delete' is used). So yes, this may be fixable by
replacing the GC.
More information about the Digitalmars-d-learn
mailing list