Limit on maximum Array size..memory leaks?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Shahmil_Merchant
Posted On:   Tuesday, August 13, 2002 08:00 AM

I have defined 2 classes called Matrix (which handles matrix functions) and Stats which does various mathematical operations on rows/columns of the matrix(like mean std_dev etc).When i use a matrix of size 5000*75 i seem to to work fine for calculating the mean of each row.However when i used a matrix of 12000*75 the CPU time on the process appears to be 18 sec (as seen from Windows task manager) but the memory usage seems to increase rapidly and remains at around 0.9G ,that too after the process seems to have finished using the CPU and returns as Exception java.lang.OutOfMemoryError: requested 30605312 bytes My understanding of garbage collection in java is that everything created by "new" is automatically taken car   More>>


I have defined 2 classes called Matrix (which handles matrix functions) and Stats which does various mathematical operations on rows/columns of the matrix(like mean std_dev etc).When i use a matrix of size 5000*75 i seem to to work fine for calculating the mean of each row.However when i used a matrix of 12000*75 the CPU time on the process appears to be 18 sec (as seen from Windows task manager) but the memory usage seems to increase rapidly and remains at around 0.9G ,that too after the process seems to have finished using the CPU and returns as
Exception java.lang.OutOfMemoryError: requested 30605312 bytes


My understanding of garbage collection in java is that everything created by "new" is automatically taken care of by the garbage collector.
Here are a few code snippets.In the test program

			

Matrix matrix1 = new Matrix(args[0]);
Stats statistics = new Stats();
double[] plz = new double[matrix1.get_num_rows()];
statistics.matrix_row_means(matrix1,plz);


The code in the statistics class is as follows

			

public void matrix_row_means (Matrix M,double[] means) {
int i;
for (i=0; i
means[i] = mean(M.get_ith_row(i), M.get_num_cols());
}

public double mean(double[] x,int length)
{
double sum=0.0;
int i;
for (i=0; i
sum += x[i];
}
if (length == 0.0) {
return 0.0;
} else {
return sum / length;
}
}
   <<Less

Re: Limit on maximum Array size..memory leaks?

Posted By:   Simon_Ablett  
Posted On:   Tuesday, August 13, 2002 09:14 AM

Firstly, you can allocate more memory for the JVM using '-Xms' and '-Xmx' command line options.

Secondly, what do you mean by 'everything created by "new" is automatically taken care of by the garbage collector'? The garbage collector will only free up the resources used by an object when it's no longer referenced. If you allocate an array of 5000 elements and fill each node of the array with an object then you have memory for the array itself (including placeholders for each node). You also have memory for each of those objects. If you want the garbage collector to remove an object before it goes out of scope then set all of its references to null. In this instance it would be mean setting a node in the array to null. You may also need to explictly invoke the garbage collector.

Regards.
About | Sitemap | Contact