Manual memory management in D2
Sean Kelly
sean at invisibleduck.org
Sun Jul 11 09:00:02 PDT 2010
"Lars T. Kyllingstad" <public at kyllingen.NOSPAMnet> wrote:
> 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*).
It may change to a template function at some point because there's no
implicit conversion from shared(void)*. I haven't completely decided
whether the user should be expected to cast when freeing shared memory.
More information about the Digitalmars-d
mailing list