Memory not freed after leaving scope for python-bioformats (.ims file type)


I am trying to use the python-bioformats package to read from a .ims image file. On reading a large number of slices a memory leak accumulates eventually causing an out of memory error.

The following code gives a minimal example of the leak

import javabridge
import bioformats

data = "/data/data.ims"
javabridge.start_vm(class_path=bioformats.JARS, run_headless=True)

with bioformats.ImageReader(data) as reader:
for i in range(10)
slice =

As I understand it, the preferred use is to bind the reader to a scope like this. I have also tried simply calling .close() afterwards instead. This code causes the Python process to accumulate a large amount of memory usage (increasing on each iteration). Killing the VM does not free the memory and the memory is only freed once the python process has ended.

Any ideas would be greatly appreciated.


While we’re waiting for an input from more expert person, can you try the following command at the end of each cycle:
It’s supposed to clear the cache memory.

Hope that helps.

Hi Minh,

No this does not seem to help.

Also I was under the impression that this function should clear the reader cache, rather than the image cache for each individual reader.


Anyone else got any suggestions for this?