Raspberry Pi Fiji "Out of Memory Error"

Hi, my first post here :slightly_smiling_face:
I have been learning ImageJ and Fiji for about a month and have been using them on a number of Windows and Linux computers. I recently installed it on a Raspberry Pi 4 (4gb) for use with the Raspberry Pi HQ camera. I am not very good with code so this would have been impossible for me without the contributions of this forum…so thanks! I am using the ImageJ.sh script to launch ImageJ. I am not using the headless option for now, but may attempt it soon.

I recently ran into the Out of Memory Error while trying to run the FFT Bandpass Filter on one of the HQ camera images, and it took me a day to figure out how to get this working, so here I am sharing what I learned (which could be the wrong for all I know).

Here is the error message:

Out of memory
All available memory (247MB) has been
used. To make more available, use the
Edit>Options>Memory & Threads command.

I tried to increase to 512m and 1024m through the Memory & Threads option, but after each restart and re-attempt the memory error still occurred. I did check the status bar, which indicated that the available memory had actually increased, but the error still persisted. I read more and discovered the problem was related to the Java heap size.
Out of Memory Error troubleshooting here:
This lead me down the path of trying to understand what variable needed to be added and where. Ultimately I found the -Xms and -Xmx variables control the minimum and maximum Java heap size and they needed to be added to the ImageJ.sh script used to launch on ImageJ on Raspberry Pi.


I added these two lines to below the "eval java $EXT_OPTION " line in the ImageJ.sh script near the bottom.
-Xms256m \
-Xmx1024m \
Restarted and my images now process without the error. I read that there may be an option to launch ImageJ with the -Xmx argument form CLI, but I could not figure that one out. Disclaimer, I have little to no idea what I am doing and hope somebody points out my terrible mistakes if I have made some :laughing:

Welcome to the forum @jcoco3 :slight_smile:

Maybe the following gives you a hint.

On Windows CLI (assuming on path of ij.jar):

java -Xmx1024m -jar ij.jar ij.ImageJ

Thank you Peter. I had read about that option for Windows CLI, and was wondering if something similar was possible in the Pi Terminal that includes the -Xmx1024m argument? From the little that I understand about the complexity of the installation on Raspberry Pi OS I assumed that use of the ImageJ.sh script was the only way to launch ImageJ on PI and my main reason for modifying the script to include those parameters…Oh wait, after more reading I think I answered my own question :grin: It was in the ImageJ.sh all along I just did not understand what I was reading.
I was able to launch ImageJ from the terminal with the memory argument using:
./ImageJ.sh --mem=1024m

Also it seems as if the option for --headless mode works similarly.
./ImageJ.sh --headless -macro path-to-Macro.ijm

Why did I not see this before :thinking:
Your hint went a long way, so thank you :+1: