On Tuesday, 6 October 2015 at 20:43:42 UTC, bitwise wrote:
For the THIRD time, I'll post my example:
class Texture { }
class Texture2D : Texture {
this() { /* load texture... */ }
~this { /* free texture */ } // OOPS, when, if ever,
will this be called?
}
Now, does this really seem like a realistic use case to you?
using(Texture tex = new Texture2D) {
// ...
}
It does, entirely. I usually translate it to D this way:
{
Texture tex = new Texture2D;
scope(exit) tex.destroy;
// ...
}
Of course, nothing protects you from passing the reference
outside the scope and having a dangling ref after the scope ends,
so it's by no means safe, but the destruction is deterministic.