How to use destroy and free.
forkit
forkit at gmail.com
Wed May 4 05:37:49 UTC 2022
On Wednesday, 4 May 2022 at 05:13:04 UTC, Mike Parker wrote:
> On Wednesday, 4 May 2022 at 04:52:05 UTC, forkit wrote:
>
>>
>> It is certainly *not* about you not having to care anymore
>> (about memory management).
>>
>
> That's not at all what I said. You don't have to care about
> *when* memory is deallocated, meaning you don't have to manage
> it yourself.
In any case, I disagree that caring about when memory gets
deallocted means you shouldn't be using GC. (or did I get that
one wrong too??)
You can have the best of both worlds, surely (and easily).
This (example from first post):
void main(){
int[] i = new int[10000];
import object: destroy;
destroy(i);
import core.memory: GC;
GC.free(GC.addrOf(cast(void *)(i.ptr)));
}
could (in theory) be replaced with this:
void main(){
inscope int[] i = new int[10000];
// inscope means 2 things:
// (1) i cannot be referenced anywhere except within this
scope.
// (2) i *will* be GC'd when this scope ends
}
More information about the Digitalmars-d-learn
mailing list