I am loading about 100 FITS images of 3000x2000 pixels and then converting the pixel values for each image into a matrix and rescaling the matrix and adding each one to a SET.
But I am quickly running out of memory in my heap. The Set of int matrices shouldn't take too much memory should it? (The heap is about 2GB I believe, at least eclipse uses 2GB before giving error.)
So my thinking is that each new Fits object is being stored in memory after each loop. but it isn't needed again after the loop finishes so I don't know why that would be the case.
Is there a way to do it without running out of memory? There would be a different number of Fits files each time the program is run.
Public Set<int[][]> rescaleFitsList(File[] fitsFileList){
Set<int[][]> rescaledFitsSet = new HashSet();
for(File fits: fitsFileList){
Fits f = new Fits(fits);
double bScale = f.getHDU(0).getBScale;
double bLinear = f.getHDU(0).getBLinear;
short[][] counts = (short[][])f.getHDU(0).getKernel();
int[][] rescaledFits = new int[counts.length][counts[0].length];
for(int i =0, i<counts.length, i++){
for(int j =0, j<counts[0].length, j++){
rescaledFits[i][j] = (int)(bScale * counts[i][j] + bLinear);
}
}
rescaledFitsSet.add(rescaledFits);
}
}