Finalize GC memory
Namespace
rswhite4 at googlemail.com
Mon Jun 17 09:46:29 PDT 2013
On Sunday, 16 June 2013 at 21:37:16 UTC, Namespace wrote:
> It seems that does what I want. The result is the same as with
> the current 'delete' implementation.
>
> ----
> void Delete(T)(ref T var) {
> static if (is(T == struct) && is(typeof(var.__dtor)))
> var.__dtor();
>
> static if (is(T : U[], U))
> core.memory.GC.free(var.ptr);
> else {
> static if (is(T : U*, U))
> core.memory.GC.free(var);
> else
> core.memory.GC.free(&var);
> }
> }
> ----
>
> But if I call 'destroy' before I call GC.free, it does not work
> correct.
I forget 'var = null;'.
But:
Any thoughts on this?
Will it work as I want?
In my few tests it seems to work like delete, but I would be
interested in the meaning of some experts.
More information about the Digitalmars-d-learn
mailing list