I have a weird memory leak problem when I am using Bioformats 5.9.2 in Matlab (R2018b). Accessing the readers multiple times is causing “java.lang.OutOfMemoryError: Java heap space” error.
Depending on Java Heap Memory settings of Matlab the error message appears earlier (for smaller heap memory settings; step 22 in the attached example when heap memory is 256 Mb) or later (for larger; step 44 in the example below when heap memory is 512 Mb).
The script below
- generates two test images (16000 x 16000 pixels)
- saves them as TIF
- generates array of bio-format readers for these 2 images: 25 sets of these two files (=50 virtual stacks, readers)
- runs 2 tests:
Test 1: in a loop loads 1500x1500 fragment from each of these 50 readers
Test 2: in a loop loads 50 times 1500 x 1500 areas from only reader 1 and 2.
Test 1 is causing the error, while the test 2 works fine. It looks that readers do not release memory after obtaining data from files. Could this be fixed?
A demo script is attached, details inside.
bio_test.m (2.4 KB)