Deallocate array?

Juan Manuel Cabo juanmanuel.cabo at gmail.com
Tue May 7 19:52:08 PDT 2013


> I found this problem with a program that reads a large xml file 
> (250000+ lines), then stores the lines in a string[], does a 
> comparison with another array and finally clears the original 
> array.
> On the second or third file I always get an OutOfMemoryError, 
> when the Task Manager shows about 1.3GB memory usage.
>
> Is this a Windows specific thing or am I doing something wrong?

Try the following before getting rid of your arrays:

       myarray[] = null; //if it is an array of classes or strings

       myIntArray[] = 0; //if it is an array of ints

       myBigString[] = '\0';

       etc.

This clears the contents of the arrays, and helps the garbage 
collector, so that it doesn't confuse data with pointers.

Also, avoid growing arrays little by little. This is VERY bad for 
garbage accumulation. Use instead an appender!(string[])() for 
string arrays for instance.

--jm


More information about the Digitalmars-d-learn mailing list