Keeps running out of memory

Hi All,
I’m trying to do a simple batch sum, 8bit convert, save macro of 20x 10GB 4D data sets (.nd2).
I keep running out of memory when I try this, when I feel it shouldn’t since it’s dealing with 10GB at a time (PC is 32GB RAM; FIJI memory 3/4). Am I missing something obvious as to why this keeps occurring? code below. Many thanks in advance! Darren

dir1 = getDirectory("Choose_ Source Directory ");
dir2 = getDirectory("Choose Destination Directory ");
list = getFileList(dir1);
for (i=0; i<list.length; i++) {
showProgress(i+1, list.length);
filename = dir1 + list[i];
if (endsWith(filename, “nd2”)) {
run(“Z Project…”, “projection=[Sum Slices]”);
saveAs(“TIFF”, dir2+list[i]);

Probably there is a time during the conversion when both the full 10GB file and the new 8bit file exist and that makes it run out of RAM? I would try increasing the memory a bit more. Or the file is 10GB but the image takes more space when displayed? There are ND2 files which are compressed.

Yeah as far as I can see you are never close the big .nd2 files you open. I believe that close command you have will only close the TIFF you created.

Could you replace it with

run("Close All");

And see if it helps? I also tend to close stuff as soon as I don’t need it, especially big files so I was you after running the projection command I would add the below.

selectWindow("SUM_" + filename);
1 Like

Hello All,
10Gb is still larger than the maximum of 8Gb allowed by either of the software used by ImageJ/Fiji and Java.

Hi @Darren_Thomson,

If @lmurphy suggestion does not do the job, you can try adding the following line at the end of the loop, after closing the images and before the next loop starts:

run(“Collect Garbage”);

1 Like