Memory leaks in batch mode

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Memory leaks in batch mode

Michael Doube
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();
}
Reply | Threaded
Open this post in threaded view
|

Re: Memory leaks in batch mode

Michael Doube
Hi All

Wayne showed me a stylistic change that prevents a new imp from being
created and taking up RAM when plugins are called from a batch mode macro.

When you call a method that returns an ImagePlus and you want to replace
the original image rather than return a whole new image in its own
window, it's better to do this:

     ImagePlus imp2 = dilate(this.image, (int)gd.getNextNumber(), false);
     image.setStack(null, imp2.getStack());

rather than:

    dilate(this.image, (int) gd.getNextNumber(), false).show();

And also better to move the new window option into the run() method.

Mike


Michael Doube wrote:

> 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
>