How to use destroy and free.

Mike Parker aldacron at gmail.com
Wed May 4 02:42:44 UTC 2022


On Tuesday, 3 May 2022 at 14:57:46 UTC, Alain De Vos wrote:
> Note, It's not i'm against GC. But my preference is to use 
> builtin types and libraries if possible,
> But at the same time be able to be sure memory is given free 
> when a variable is going out of scope.
> It seems not easy to combine the two with a GC which does his 
> best effort but as he likes or not.

What I described is an optional compiler optimization. The 
compiler is free to avoid the GC allocation for an array literal 
initializer if it is possible to do so. If you were to, e.g., 
return the array from the function, it would 100% for sure be 
allocated on the GC and not the stack. In practice, I don't know 
if any of the compilers actually do this.

Anyway, if you care when memory is deallocated, then the GC isn't 
the right tool for the job. The point of the GC is that you don't 
have to care.


More information about the Digitalmars-d-learn mailing list