How to allocate/free memory under @nogc

Adam D. Ruppe destructionator at gmail.com
Thu May 21 03:04:16 UTC 2020


On Thursday, 21 May 2020 at 02:50:22 UTC, data pulverizer wrote:
> Can you also confirm that `@nogc` in a class do the same thing 
> in that class as it does for a function?

I don't think it does anything in either case, but if it does 
anything it will just apply @nogc to each member function in them.

> Is `data` in `MyType` tracked by the garbage collector?

Yes, it is tracked. What @nogc does is prohibit calling that 
function from ever calling the GC's collect method. It doesn't 
affect what is and isn't collected when that is eventually called 
somewhere else.

> If it is how do I allocate it in such a way that it is not?

though you can malloc memory to hide it from the GC, you 
generally shouldn't.

Note that in your example if T is ubyte or some other trivial 
value type it isn't scanned anyway since the static type info 
tells it it will never contain pointers/references.


More information about the Digitalmars-d-learn mailing list