CellProfiler 4.0 JVM heap space error

Hey everyone,
I have 150 time series loaded, extracting of the metadata works fine and Names and Types module gives me the correct number of image sets (~ 16.000 image sets).
After I start Analyze Images, after a long loading time where CP is not responding I get a direct error message:

Encountered unrecoverable error in Metadata during startup:
Java heap space

I tried to increase the size of the Jave heap space in the ways written in this post

It is not working through command line and I also cannot find anything about Java memory in the CellProfiler preferences.
What is the correct way for CellProfiler 4 (I have version 4.0.7) to increase the Java heap space?

Thanks in advance


Hi @ChristinaC,

Here are the details for updating this in CellProfiler 3. We’ve now removed the option in CellProfiler 4, unfortunately.

In CP3, you open the CellProfiler menu > “Preferences”, you should see an option named “Maximum memory for Java” where you can adjust this setting. The screenshots below provide more detail. Hope this helps and let us know if you have other questions.

Screen Shot 2021-03-31 at 9.42.19 AM

Whoops @ChristinaC, that answer was not correct! I inadvertently opened CellProfiler 3 when writing that answer. Please disregard!

Hi @ChristinaC

As of CellProfiler 4.0 the internal setting for specifying Java heap size was removed. We used to default this to 512mb, but modern Java installations should do a better job of setting this automatically to be 1/4 of your system’s memory. Now that hardware has advanced the old default would have been much smaller than most machines would allocate normally, so the setting was retired.

It’s still possible to manually override heap size by using environment variables. These can be set globally (via Control Panel on Windows), or just within the command prompt. If you’re on Windows and wanted to try a temporary setting, you’d type set _JAVA_OPTIONS=-Xmx2g in command prompt and then start cellprofiler from the same window (type cellprofiler). In this example ‘2g’ would specify a heap max of 2gb.

Generally speaking, I’d take care in increasing Java memory far beyond the default, since this risks limiting the amount of memory left for CellProfiler to work with. You might want to try breaking your analysis up into smaller “chunks” either through limiting the number of image sets or perhaps using the Groups module.

Hope that helps

1 Like

Hi @DStirling
thanks for your answer. I haven’t tried to increase heap size with the instruction you gave because of the concers you have raised. But I broke down my analysis and just analyze half of my images in one analysis run. And I read in the preferences help that usage of fewer workers can help, so I use only 4 instead of 8 workers and it’s running now without errors