Segmentation error at the end problem (148 line program listing)
Daniel Keep
daniel.keep.lists at gmail.com
Sat Jan 31 07:07:37 PST 2009
grauzone wrote:
> 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;
If you're going to do that, you really should make the it a scope class
to ensure you never accidentally let the GC try to delete it.
I (and a few others) petitioned what feels like years ago for a simple
argument to dtors to distinguish between deterministic destruction
(delete/scope) and automatic destruction (GC). Never gained any ground,
sadly.
-- Daniel
More information about the Digitalmars-d-learn
mailing list