GC-proof resource classes
ponce via Digitalmars-d
digitalmars-d at puremagic.com
Mon Aug 31 06:35:52 PDT 2015
On Monday, 31 August 2015 at 12:54:05 UTC, Sebastiaan Koppe wrote:
> What about:
>
> ```
> class MyResource
> {
> void* handle;
> this()
> {
> handle = create_handle();
> }
> close()
> {
> if (handle)
> free_handle(handle)
> handle = null;
> }
> ~this()
> {
> enforce(!handle,"Resource leak");
> }
> }
> ```
Unique!T destructor calls delete which calls ~this() not close()
RefCounted!T and scoped!T call .destroy which calls ~this() not
close()
We really want one thing there.
More information about the Digitalmars-d
mailing list