Segmentation error at the end problem (148 line program listing)
grauzone
none at example.net
Sat Jan 31 05:46:17 PST 2009
The garbage collector isn't guaranteed to to free and destroy an
unreachable object. That's because the GC is conservative. So if you
want to be sure the object's resources are freed, you have to do it
explicitly.
I think you have two choices:
1. Remove close() from the destructor, and call close() manually when
you're done.
2. Use scope or delete to ensure the destructor is always directly
called, and never by the GC.
Here's how you can use scope:
{
scope BlockFile f = new BlockFile(...);
//... do something with f
} //f goes out of scope, and the compiler inserts delete f;
More information about the Digitalmars-d-learn
mailing list