Manual memory management in D2

Petr janda.petr at gmail.com
Sat Jul 10 20:53:12 PDT 2010


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()?

2) What is D's equivalent of C++ std::memory? If there's none, what are the implications of using C's malloc and free
in D as opposed to in C, if any?

Thanks,
Petr


More information about the Digitalmars-d mailing list