Dear all,
Is there any way to 'flush out' the memory at the start of a macro/for loop? My macros keep coming up with problems that do not occur if I run things manually in exactly the same routine!? For example, on some occasions, it says that run("Create Selection") needs a thresholded/binary image. I have set this up correctly: setAutoThreshold(); run("Analyze Particles...", "size=5000-Infinity circularity=0.00-1.00 show=Masks exclude clear include"); mask = getImageID; run("Copy"); setPasteMode("AND"); selectImage(img1); run("Paste"); resetThreshold(); selectImage(mask); run("Create Selection"); // requires 1.37j on other occasions, with the same dataset, it gets passed this point!? There's also a convex hull problem. Initially, I found that to run: run("Enlarge...", "enlarge=0"); run("Fit Spline"); prior to: run("Convex Hull"); seems to solve the closed/polyline/polygon ROI problem. This, however, is sometimes reoccurring?! Strange?! My only thought is that it is a memory problem... Cheers, Andy |
Hello Andy,
Yes, there is a way to flush memory within a macro (to manually force the JVM to do "garbage collection"). The JVM is supposed to do garbage collection automatically when necessary, but as you have found it, it doesn't always do it. So you can manually do an operation or process successfully, but then run into memory errors when you automate it via macro functions. It is very easy to force garbage collection via a plugin, and perhaps with the newish "call" macro function, but I am pretty much macro-limited. So last year when I ran into this problem, I prepared a small tool to help us macro-limited folks. You can find more details in the mailing list archives, specifically topic 139 in the archives from June 2005 (see https://list.nih.gov/cgi-bin/wa?A1=ind0506&L=imagej#139). Curiously, you don't report that ImageJ actually gives you an "out of memory" error which is what I see. But maybe things have changed with newer IJ versions. Mark Besonen UMass Geosciences At 12:22 PM 7/27/2006, you wrote: >Dear all, > >Is there any way to 'flush out' the memory at the start of a macro/for >loop? > >My macros keep coming up with problems that do not occur if I run things >manually in exactly the same routine!? > >For example, on some occasions, it says that run("Create Selection") >needs a thresholded/binary image. I have set this up correctly: > > setAutoThreshold(); > run("Analyze Particles...", "size=5000-Infinity circularity=0.00-1.00 >show=Masks exclude clear include"); > mask = getImageID; > run("Copy"); > setPasteMode("AND"); > selectImage(img1); > run("Paste"); > resetThreshold(); > selectImage(mask); > run("Create Selection"); // requires 1.37j > >on other occasions, with the same dataset, it gets passed this point!? > >There's also a convex hull problem. Initially, I found that to run: > > run("Enlarge...", "enlarge=0"); > run("Fit Spline"); > >prior to: > > run("Convex Hull"); > >seems to solve the closed/polyline/polygon ROI problem. This, however, >is sometimes reoccurring?! > >Strange?! My only thought is that it is a memory problem... > >Cheers, Andy |
Hello Andy and others,
I just bothered to investigate the newish "call" macro function that I mentioned in my last message, and in fact, it is a much more elegant solution than the kludge I pointed you to originally. Take a look at the CallJavaDemo.txt macro example (http://rsb.info.nih.gov/ij/macros/CallJavaDemo.txt). To provoke garbage collection from within a macro nowadays is as simple as: call("java.lang.System.gc"); Sorry for steering you in the wrong direction initially--I'd definitely suggest you use the "call" function instead nowadays. Mark Besonen UMass Geosciences At 12:58 PM 7/27/2006, Mark R. Besonen wrote: >Hello Andy, > > Yes, there is a way to flush memory within a macro (to > manually force the JVM to do "garbage collection"). The JVM is > supposed to do garbage collection automatically when necessary, but > as you have found it, it doesn't always do it. So you can manually > do an operation or process successfully, but then run into memory > errors when you automate it via macro functions. > > It is very easy to force garbage collection via a plugin, > and perhaps with the newish "call" macro function, but I am pretty > much macro-limited. So last year when I ran into this problem, I > prepared a small tool to help us macro-limited folks. You can find > more details in the mailing list archives, specifically topic 139 > in the archives from June 2005 (see > https://list.nih.gov/cgi-bin/wa?A1=ind0506&L=imagej#139). > > Curiously, you don't report that ImageJ actually gives you > an "out of memory" error which is what I see. But maybe things > have changed with newer IJ versions. > >Mark Besonen >UMass Geosciences > > > > >At 12:22 PM 7/27/2006, you wrote: >>Dear all, >> >>Is there any way to 'flush out' the memory at the start of a macro/for >>loop? >> >>My macros keep coming up with problems that do not occur if I run things >>manually in exactly the same routine!? >> >>For example, on some occasions, it says that run("Create Selection") >>needs a thresholded/binary image. I have set this up correctly: >> >> setAutoThreshold(); >> run("Analyze Particles...", "size=5000-Infinity circularity=0.00-1.00 >>show=Masks exclude clear include"); >> mask = getImageID; >> run("Copy"); >> setPasteMode("AND"); >> selectImage(img1); >> run("Paste"); >> resetThreshold(); >> selectImage(mask); >> run("Create Selection"); // requires 1.37j >> >>on other occasions, with the same dataset, it gets passed this point!? >> >>There's also a convex hull problem. Initially, I found that to run: >> >> run("Enlarge...", "enlarge=0"); >> run("Fit Spline"); >> >>prior to: >> >> run("Convex Hull"); >> >>seems to solve the closed/polyline/polygon ROI problem. This, however, >>is sometimes reoccurring?! >> >>Strange?! My only thought is that it is a memory problem... >> >>Cheers, Andy |
Free forum by Nabble | Edit this page |