Deallocate array?
Matic Kukovec
matic.kukovec at pametnidom.si
Wed May 8 03:20:45 PDT 2013
Was playing around with the code and found that this WORKS:
(note the "app_temp_array.reserve(50000000);" at the top, without
this line it doesn't work)
import std.stdio, core.memory, std.cstream, std.array;
void main()
{
string[] temp_array;
Appender!(string[]) app_temp_array = appender(temp_array);
app_temp_array.reserve(50000000);
for(int i=0;i<50000000;i++)
{
app_temp_array.put("aaaaaaaaaaaaaaaaaaaaa");
}
temp_array = app_temp_array.data;
app_temp_array.clear();
GC.free(app_temp_array.data); or GC.free(temp_array.ptr);
GC.collect();
GC.minimize();
writeln("end");
din.getc();
}
The memory usage shrinks from 400MB to 2MB, which is right!
Why?
More information about the Digitalmars-d-learn
mailing list