How to get nogc to work with manual memory allocation

Bienlein via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 24 02:32:17 PDT 2014


On Sunday, 24 August 2014 at 08:48:03 UTC, bearophile wrote:

> Perhaps there are ways, but note that @nogc is meant mostly for 
> stack-allocation.

Ah, I missed that. Thanks for telling me. I changed nogcDel now 
to null out the deallocated object:

void nogcDel(T)(ref T obj)
{
     import core.stdc.stdlib : free;

     // calls obj's destructor
     destroy(obj);

     // free memory occupied by object
     free(cast(void*)obj);

     obj = null;
}

And now I also get the dearly missed protection violation ;-).


More information about the Digitalmars-d-learn mailing list