ImageJ memory problem

Hi,
I had a memory leak calling RunImageJ some time ago which was solved by running commands as macros written entirely within the pipeline (instead of plugins).
However, I now need to run a plugin in ImageJ and every time it’s called for a 1390x1040 image the ImageJ memory usage accumulates by 7MB.
The plugin is installed in ImageJ and called from the pipeline (attached) as macro:
call(“Qi_Segmenter.setDistance”,5);
run(“Qi Segmenter”);
(the first line just sets a plugin parameter).
Calling ConserveMemory to delete the returned image makes no difference.
Thanks very much for any help
Best
Carlos
ImageJ_simple.cpproj (79.1 KB)

Hi Carlos,
I can look at this in more detail, but can you run the rough sequence of ImageJ commands that you’re issuing from CellProfiler and see if ImageJ also suffers from a memory leak? It might be a problem with the plugin in which case, perhaps the author might help. If not, I’ll take a look at it.

Hi Lee,
Thanks for your reply.
I wrote the plugin, it’s an implementation of a segmentation and I’m happy to send either source or compiled if it helps.
However, it cannot be repeated as a series of ImageJ commands as some operations are very specific to the algorithm. I cannot write it as a macro either (I mean, perhaps I could, but it would take days to write and longer to run!)
The plugin doesn’t leak in standalone ImageJ. The output is written into the input image itself (it has a method that duplicates an ImageProcessor but should be garbage collected on return - and as far as I can see it is).
I had found some time ago that calling plugins progressively increases the ImageJ memory usage but if the same operations are 1) written as a macro and 2) the macro is inserted into the pipeline (instead of being called from an installation in the ImageJ plugins directory), then there’s no memory leak.
Thanks very much for any help and please let me know if there are any tests I should run or any information I should send.
Best
Carlos

Hi Lee,
I found a way around my RunImageJ memory problem, although I’m still not sure it’s due to something I’m doing wrong!
In case it’s of any interest, this is what happened.
It seems that every time an image is exported to ImageJ, 2 ImagePlus are recorded by WindowManager, both with exactly the same image ID.
For each pair of entries one is a proper ImagePlus, with its ImageProcessor and ImageWindow, but the other ImagePlus has no ImageProcessor and no ImageWindow (both null). Both “good” and “bad” ImagePlus can be retrieved using WindowManager.getImage(id) and the “bad” ImagePlus still have a title, width and height (so they still take a bit of memory but not much).
Now, any module command I tried to make ImageJ close (all) images at the end of each cycle fails, apparently due to these “bad” windowless ImagePlus in the ID list that WindowManager keeps.
The beanshell script below looks into the ID list and closes the ImagePlus that have an ImageWindow, and that releases most of the memory.
Setting the ImagePlus without ImageWindow to null seems to release a bit more memory.
I couldn’t find a way to remove the “bad” windowless ImagePlus from the ID list, which keeps growing in size, but doesn’t take much memory (roughly 20MB per 100 images, which is Ok for me).
So, not an ideal solution, but it works.
Best
Carlos

[code]import ij.IJ;
import ij.WindowManager;
import ij.ImagePlus;
import ij.gui.ImageWindow;

int] ids = WindowManager.getIDList();
if(ids != null) { // Just in case it returns null list - though I haven’t seen this
for(int id:ids) {
ImagePlus imp = WindowManager.getImage(id);
ImageWindow win = imp.getWindow();
if(win!=null) {
imp.changes = false;
imp.close();
} else {
imp = null;
}
}
}[/code]