Prevent Garbage Collector

Adam D. Ruppe destructionator at gmail.com
Sat Jan 4 09:16:52 PST 2014


On Saturday, 4 January 2014 at 17:15:12 UTC, Jeroen Bollen wrote:
> Is there a way to prevent the Garbage collector from running on 
> one particular object? Something like:

I would just malloc it.

int* CreatePermanentInt() {
    int* i = malloc(int.sizeof);
    *i = 5;
    return i;
}


The malloced thing itself won't be freed, nor will its contents 
be scanned by the gc (unless you use GC.addRange yourself) so you 
can use it to hack some weak references too.


More information about the Digitalmars-d-learn mailing list