Deallocate array?

Minas Mina minas_mina1990 at hotmail.co.uk
Wed May 8 01:59:55 PDT 2013


On Tuesday, 7 May 2013 at 23:09:29 UTC, Matic Kukovec wrote:
> Hi
>
> I'm running Windows Vista 64 with dmd 2.062.
>
> I have a simple program:
>
> import std.stdio, core.memory, std.cstream;
> void main()
> {
> 	string[] temp_array;
>
> 	for(int i=0;i<5000000;i++)
> 	{
> 		++temp_array.length;
> 		temp_array[temp_array.length - 1] = "aaaaaaaaaaaaaaaaaaaaa";
> 	}
> 	
> 	temp_array = null;
>
> 	GC.collect();
>         writeln("end");	
> 	din.getc();
> }
>
> When the program waits at "din.getc();", memory usage in the 
> Task Manager is 150MB.
>
> Why isn't the memory deallocating?
>
> P.S.;
> I tried temp_array.clear() and destroy(temp_array), but nothing 
> changed.

I guess the memory isn't freed because there is no need to do so. 
A garbage collector kicks in when there is not enough memory. In 
this case there is no need to.


More information about the Digitalmars-d-learn mailing list