Segmentation error at the end problem (148 line program listing)

grauzone none at example.net
Fri Jan 30 04:41:37 PST 2009


Charles Hixson wrote:
> I replaced BlockFile.close with:
>    void  close()
>    {  if (bf !is null)  delete bf;        //    bf.close;
>       bf =  null;
>    }
> 
> But that didn't alter the segmentation fault.  (Did you try it under D1 
> or D2?)

Your destructor calls close(), and close() accesses the reference bf. 
But accessing references is not allowed in destructors. I think "delete 
bf;" still counts as accessing a reference.

The reason is, that the garbage collector calls the destructor, when an 
object becomes unreachable. The order the destructors are called is 
undefined. References to other objects may no longer be valid, because 
these objects were already destroyed.


More information about the Digitalmars-d-learn mailing list