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;