Mem Mgmt: With & Without the GC
Cauterite via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Aug 21 10:55:10 PDT 2016
On Sunday, 21 August 2016 at 16:14:53 UTC, Zane wrote:
> 1) If using the GC, but for whatever reason, I need to free
> something _right now_, is core.GC.free() the proper way to do
> this?
The main problem is that `new` does not necessarily give you a
pointer to the start of an allocation, and `GC.free()` does not
work if you give it a pointer to the interior of an allocated
block.
You could use `GC.addrOf()` to get the base address from an
interior pointer, but I don't know whether there could be other
objects/arrays sharing the same memory block.
If you explicitly allocated the memory block yourself with
`GC.malloc()` then you have full control over what is placed in
it and can safely `GC.free()` the memory using the base address.
Keep in mind, `GC.free()` does not call finalisers.
More information about the Digitalmars-d-learn
mailing list