Manual memory management in D2

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Sun Jul 11 05:03:39 PDT 2010


On Sun, 11 Jul 2010 03:53:12 +0000, Petr wrote:

> Hi all,
> 
> I know this has been discussed million times before, but there is so
> many posts on the mailing lists on this subject and all of them
> different, its kind of hard to find what's authoritative and whats not.
> TDPL doesn't really talk much about this subject either, it just says
> the delete keyword is deprecated, and that clear() doesn't free memory,
> and that there is GC.free() which explicitly frees memory.
> 
> Say we have a class C, which is constructed and allocated using: C* c =
> new C(). I understand c is allocated on the GC heap. What if I do want
> to explicitly free it, and not wait for the GC to kick in? Assuming that
> delete is gone,
> 
> 1) Do i do clear(c) and then GC.free(c)? What would happen if i skipped
> clear()?


Strictly speaking, you have to call GC.free(cast(void*) c), since c is a 
reference (C) and not a pointer (C*).

-Lars


More information about the Digitalmars-d mailing list