grauzone wrote:
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.

Hmmm.... reasonable. Any idea how I should handle it? I want to ensure that the file is closed when the container is released. Maybe just get rid of the close method? But the garbage collector isn't guaranteed to run at any particular time...(OTOH, I am doing GC.collect...it would be nice to find a way to get rid of that, too. Maybe I could solve this by moving GC.collect inside the delete method, and not doing anything else there?)

Didn't work.  And when I added:
writefln ("after writefln");
into the main program after "writefln (\"after second open\");"
it had a segmentation error before reaching the "after writefln"

Reply via email to