How to use destroy and free.

forkit forkit at gmail.com
Wed May 4 04:52:05 UTC 2022


On Wednesday, 4 May 2022 at 02:42:44 UTC, Mike Parker wrote:
> 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.

GC is about reducing the complexity, cognitive load, and possible 
bugs - associated with manual memory management.

It is certainly *not* about you not having to care anymore (about 
memory management).

Why not have an option to mark an object, so that real-time 
garbage collection occurs on it as it exits scope?


More information about the Digitalmars-d-learn mailing list