grauzone wrote: > Daniel Keep wrote: >> [snip] >> >> 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. > > I think it'd be even better to make them different functions. The > finalizer could just be a virtual function called finalize(). Really, > the differences between proper destructors and finalizers should be > large enough to justify separate functions. > > Or even better, ditch finalizers and their wacky semantics (which make > them quite useless anyway), and invent something like notify-able > weakpointers. D already provides basic support for this > (Object.notifyRegister()), but I think in Phobos 1.0 it's a bit buggy. > There were some issues with race conditions and locking.
Personally, I'd be happy if I could get this to work: class Foo : Disposable { void dispose() { // do cleanup } ~this(bool deterministic) { if( deterministic ) { if( ! isDisposed ) dispose; } else if( ! isDisposed ) throw new DisposeException("You forgot to dispose, you thick burke!"); } } -- Daniel