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
>