Mem Mgmt: With & Without the GC

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 21 23:13:14 PDT 2016


On Sunday, 21 August 2016 at 19:30:51 UTC, Guillaume Piolat wrote:

>> 5) Is there a way to do simple heap allocation with 'new' 
>> while ensuring the GC doesn't deallocate until I want it to?
>
> Keep a reference somewhere reachable (by default: stack, heap, 
> globals: everything is reachable and scanned).
>

Or just tell the GC directly not to collect it via GC.addRoot:

https://dlang.org/phobos/core_memory.html#.GC.addRoot


More information about the Digitalmars-d-learn mailing list