Login  Register

Memory leaks in batch mode

Posted by Michael Doube on Oct 21, 2009; 8:57am
URL: http://imagej.273.s1.nabble.com/Memory-leaks-in-batch-mode-tp3690644.html

Dear all

I have a macro that includes calls to Erode 3D and Dilate 3D, from VIB_.jar

When I run my macro in batch mode (setBatchMode(true)) on a directory of
100 images, I get an out of memory error after about the 40th image.  If
I remove Erode and Dilate 3D from my macro, I can complete the job.  It
seems like Erode and Dilate 3D are leaving about 25 MB hanging about in
RAM after each iteration (1000 MB / 40 iterations).  Once my macro has
finished I can manually garbage collect by clicking on the ImageJ status
bar, which works fine.

I see that these plugins are PlugInFilters and have class variables for
the ImagePlus and a couple of work arrays.

Is there a stylistic change to be made to these plugins that would
prevent this problem?

Mike

-------------
dir1 = getDirectory("Choose Source Directory ");
list = getFileList(dir1);
setBatchMode(true);
for (i=0; i<list.length; i++) {
         showProgress(i+1, list.length);
         open(dir1+list[i]);
         title = getTitle();
         run("Optimise Threshold", "  apply threshold tests=11
range=0.25 subvolume=256");
         run("Purify", "chunk=2");
         run("Erode 3D", "iso=255");
         run("Purify", "chunk=2");
         run("Dilate 3D", "iso=255");
         run("Volume Fraction", "start=1 end="+nSlices());
         run("Isosurface", "resampling=2");
         close();
}