Hi Stephane
Thanks for replying, shame I haven't missed something obvious! I hadn't worked out how to call the garbage collector in Javascript, so I'll throw in a couple of System.gc() for luck between steps, but forcing it once the script finishes hasn't worked so far. I had a go at taking out some sections of code and seeing where the memory was leaking:
*1.6Gb of memory bleed in Median filter plugin of 3 x channels:
(function(){
var median = new MedianFilter();
gui.closeAllViewers()
for (i = 0; i < Chns.length; ++i) {
if (median.isHeadLess()) median.createUI() //First instance create UI to generate viewer
median.Median_filter_3D(Chns[i], 2)
//WAIT//
do {} while (gui.getActiveSequence() == null)
Chns[i] = gui.getActiveSequence()
gui.closeSequence(Chns[i])
println('Median Filtered Ch: ' + i)
}
gui.closeAllViewers()
median = null
})();
*0Gb in maths (using several mathsChns[0] = Functor2.parse(formula).apply(Chns[1], Chns[0]))
*1.5Gb in distance mapping of one channel:
(function(){
...
distmap[i] = new Sequence()
distmap[i] = roimap.newInstance().createDistanceMap(Chns[i], false, false, true)
...
if (!(typeof distmap[i] == 'undefined')) Chns[Chns.length] = SequenceUtil.convertToType(distmap[i], DataType.DOUBLE, null)
...
distmap[i] = null
})();
*0Gb in saving the image
So I can find about 1/3 of the memory leaking in calling two plugins, it's just some steps rely on others so I struggle to get it to run still if I take them out, but I could try and work something out to test. I've attached the script (sorry it wouldn't take it as a .js file before) in case you see anything obvious. I'm not sure if I'm not calling something from those plugins to help them clear the memory or I haven't properly destroyed all references to them, but certainly if you use them properly from the GUI I don't get memory problems.
Any ideas greatly appreciated!
Cheers
Tamlyn