Segmentation fault on closing file in destructor

Tom Kazimiers 2voodoo at gmx.de
Sun Sep 26 08:17:07 PDT 2010


Hi Simen,

On 09/26/2010 04:06 PM, Simen kjaeraas wrote:
> Likely, it is this[1]:
> 
> "[T]he order in which the garbage collector calls destructors for
> unreference objects is not specified. This means that when the garbage
> collector calls a destructor for an object of a class that has members
> that are references to garbage collected objects, those references may
> no longer be valid. This means that destructors cannot reference sub
> objects."
> 
> [1]: http://digitalmars.com/d/2.0/class.html#destructors

thanks for your reply. I did not know that the garbage collector works
that way. Is the reason for that flexibility for the GC? What if I want
to handle some destruction parts to sub-objects or if I want conditions
while destruction, based on sub-objects? Or maybe I should generally
avoid situations like that. Do you have any suggestion how I should make
sure that the file gets closed on destruction?

Cheers,
Tom


More information about the Digitalmars-d-learn mailing list