Deallocate array?

Matic Kukovec matic.kukovec at pametnidom.si
Wed May 8 01:22:34 PDT 2013


Thanks you guys for all the suggestions.

bearophile:
I am not creating 64 bit binaries. Tried compiling with or 
without the "-m32" flag.
I have played around with GC.free, see below for more details.

Juan Manuel Cabo:
I tried your methods, but no change.
The original program I described earlier used an Appender, but 
the result is the same.
I also copy/pasted the code twice (with or without 
GC.minimize()), to see if D was just reusing the memory, but the
memory jumped to 290MB so it is not being reused or freed.

Steven Schveighoffer:
I used the "++temp_array.length;" example, because it was 
straight from the dlang.org docs. In my original program i tried 
the "~=" first then an Appender.
In this example, if i use the "temp_array ~= 
"aaaaaaaaaaaaaaaaaaaaa";" the memory usage goes down from 150MB 
to about 80MB. Then i added:
temp_array = null;
GC.free(temp_array.ptr);
GC.minimize();
The memory goes down to about 40MB! But why not lower?
It also shrinks from 150MB to 100MB with the original 
"++temp_array.length;" apending to the array.
The program in now:
import std.stdio, core.memory, std.cstream;
void main()
{
	string[] temp_array;

	for(int i=0;i<5000000;i++)
	{
		temp_array ~= "aaaaaaaaaaaaaaaaaaaaa";
	}
	
	temp_array[] = null;
	
	GC.free(temp_array.ptr);
	GC.minimize();
	
	writeln("end");	

	din.getc();
}

Any ideas?



More information about the Digitalmars-d-learn mailing list