[ImageJ-bugs] [Bug 1203] memory leak with python script

bugzilla at fiji.sc bugzilla at fiji.sc
Tue Dec 8 23:08:59 CST 2015


http://fiji.sc/bugzilla/show_bug.cgi?id=1203

--- Comment #3 from Aryeh Weiss <aryeh at cc.huji.ac.il> ---
Concerning the python.jar:
This was added whenI needed to evaluate a python script from a plugin - 
    eval("python", script);
When I did this, it prompted me that I to install Jython.jar, and it even was
kind enough to do it for me.

Motivated by Mark's comment, I renamed that jython to python.old, and copied
the Jython snapshot file (which was in jars) to the plugin/jars directory (and
renamed that one to jython.jar). The results are the same for my minimal script

I modified my minimal script to run the gc, and then close the image and runthe
gc again (twice). 

So here is the new script:
from ij import IJ, Prefs, ImagePlus
from ij.io import DirectoryChooser,  OpenDialog
from ij.process import ImageConverter, ByteProcessor, BinaryProcessor
import time, gc

def forceGc():
    print "memory before gc = ", IJ.currentMemory()
    gc.collect()
    print "memory after gc = ", IJ.currentMemory()


op = OpenDialog("Choose input image...", "")
path = op.getDirectory()+ op.getFileName()
inputName = op.getFileName()
inputDir = op.getDirectory()
inputPath = inputDir + inputName

if inputName[-4] == ".":
    inputPrefix = inputName[:-4]    # assumes that a suffix exists
else:
    inputPrefix = inputName


inputImp = ImagePlus(inputPath)
inputImp.show()
ImageConverter(inputImp).convertToGray8()

# The following line makes all the difference.
inputIp = inputImp.getProcessor()
forceGc()

inputImp.close()
forceGc()
forceGc()


and here is the output with an image of about 1 GB:

Started minimal.py at Wed Dec 09 07:06:54 IST 2015
memory before gc =  1037433016L
memory after gc =  1042983208L
memory before gc =  1058432336L
memory after gc =  1044836632L
memory before gc =  1044836632L
memory after gc =  1041655776L

## end offers run on "fresh" Fiji 

Started minimal.py at Wed Dec 09 07:07:12 IST 2015
memory before gc =  2055344376L
memory after gc =  1044025032L
memory before gc =  1056477256L
memory after gc =  1042805472L
memory before gc =  1042971816L
memory after gc =  1036835368L

## end of second run -- nothing open

Wayne -- can you run this script and post the result?

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://imagej.net/pipermail/imagej-bugs/attachments/20151209/4bd0e639/attachment.html>


More information about the Imagej-bugs mailing list