reclaim memory to os which allocated with new
ota
orhantahsinakcebe at gmail.com
Thu Oct 22 08:15:55 UTC 2026
Hi
A lot of try and finally i found that:
When i used __delete(), and GC.minimize() which reclaims memory
to os and while checked with gnome system monitor; i see that all
memory is reclaimed.
For example:
`
import std.stdio;
import core.thread;
import core.memory;
void main() {
int[] ints = new int[500_000_000]; // about 2 GB
writeln("allocated...");
for (int j = 0; j < 500_000_000; ++j) {
ints[j] = j;
}
writeln("assigned...");
Thread.sleep(5.seconds);
writeln("now 5 seconds sleeped...");
__delete(ints); // removing...
GC.minimize(); // reclaming
writeln("memory is freed...");
Thread.sleep(5.seconds);
writeln("5 seconds more sleeped...");
writeln("finishing...");
}`
Checkable with monitor tools for whether works or not.
`ints = null`, `GC.free(cast(void *)ints)` didn't work.
Just in case i wrote that for use.
Thanks.
ota
More information about the Digitalmars-d
mailing list