Segmentation fault on closing file in destructor

Simen kjaeraas simen.kjaras at gmail.com
Sun Sep 26 07:06:33 PDT 2010


Tom Kazimiers <2voodoo at gmx.de> wrote:

> Hi,
>
> a file reading class of mine can be constructed with a filename as
> parameter. It instantiates a new std.stream.File (without the passed
> file name and closes it when opened within the destructor. The last part
> is where things are getting unclear for me. On the "file.isOpen()" call
> in the destructor a segmentation fault occurs. What is the problem with
> that?

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

-- 
Simen


More information about the Digitalmars-d-learn mailing list