Advice wanted on garbage collection of sockets for c++ programmer using D
Guillaume Piolat via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jun 27 17:05:20 PDT 2017
On Tuesday, 27 June 2017 at 23:54:50 UTC, Moritz Maxeiner wrote:
>
> Do you mean destructors?
Yes.
> - Replace calls by the GC to `~this` with calls to `finalize`
> (or invent some cool other shortened name for the latter)
My point is that in such a "finalize()" function the only sane
things to do is to crash if the resource wasn't freed already.
Why so?
See my texture example in:
https://forum.dlang.org/post/kliasvljzwjhzuzibuae@forum.dlang.org
More simply:
If A needs an alive B to be destroyed, then neither A-owns-B or
B-owns-A can guarantee the ordering under GC destruction.
Furthermore, this is viral. Whoever owns A needs an alive B to be
destroyed.
> - Reserve `~this` for being called by deterministic lifetime
> management (std.experimental.allocator.dispose, object.destroy,
> RefCounted, Unique, etc.)
That's precisely what the GC-proof-resource-class allows, by
preventing defective, non-composable usages of ~this.
More information about the Digitalmars-d-learn
mailing list