Destructors called by the GC enjoy a variety of limitations and relying on them is dangerous.
class Resource { ~this() { if (!alreadyClosed) { if (isCalledByGC()) assert(false, "Resource release relies on Garbage Collection"); alreadyClosed = true; releaseResource(); } } }
See Implementation
Destructors called by the GC enjoy a variety of limitations and relying on them is dangerous.