Using Arduino IDE in Raspberry Pi gives java heap space error

Is there a way to increase the java heap space for the Arduino IDE?

Feel free to read this link

https://stackoverflow.com/questions/55109837/error-when-trying-to-run-arduino-ide-on-raspberry-pi

It looks like the same (or at least a similar) problem...

Good luck!

Thanks for the link. I wish it would have help but I couldn't do this step because the file didn't exist....

edited /usr/bin/arduino and added -Djava.library.path=/usr/lib/jni to the java command.

I found this regarding Java configuration

https://alvinalexander.com/blog/post/java/java-xmx-xms-memory-heap-size-control/

However, I guess there might be a misunderstanding...

/usr/bin/arduino is the directory where the IDE is started from. In this directory you should find a java command which should be edited as follows

java -Djava.library.path=/usr/lib/jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel processing.app.Base "$@"

Please check again and good luck!

Thank you for staying with me on this one.
I cannot find a file with a java command to edit.
I did a global search of every file in my Raspberry Pi Zero for the key words "-Xms" or "-Xmx"
None were found.
also, if I do a cd /usr/bin I do not even see an arduino directory. It is so odd because the arduino IDE runs when I click on the ICON.

You may try this command

[https://linuxize.com/post/whereis-command-in-linux/?utm_content=cmp-true](https://linuxize.com/post/whereis-command-in-linux/?utm_content=cmp-true

Trial and Error (at the moment more error...) :wink:

[Edit]: I have searched my RPi4 installation and found the file you are (should be) looking for: It is in the directory /usr/bin and its name is arduino!

Just open and edit the file with the command

  sudo nano /usr/bin/arduino

I assume that the nano editor is installed on your Raspi. Otherwise use another editor.

Make a copy of the file and then change the original as mentioned above ...

Good luck

This works also if you like a nicer GUI:

sudo thonny /usr/bin/arduino

I used your command "whereis" and found the ardunio file in /usr/local/bin
which is different from your locatoni of /usr/bin

But I opened the arduino file and I pasted your command at the bottom:
java -Djava.library.path=/usr/lib/jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel processing.app.Base "$@"

I still get Java heap space. The whole error looks like this:
Exception in thread "Timer -0" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copfOf(Arrays.java:3236)
...

More information: The Java Heap Space error only seems to happen when I first open the Arduino IDE and compile my code for the first time. After that (e.g. the very next compile), no error anymore. Maybe I just live with it?

At least for the moment. Usually errors like this come back ... :wink:

Maybe someone will pop up sooner or later who knows what to do. As I do not have your constellation my support is just guess work.

Good luck and have fun with Arduino and Raspberry Pi.

Hi @robertgaines

I'm not sure about that.

What you can do is adjust the heap space configuration of Arduino IDE though. This is what people do to overcome the heap space error you get when attempting to start Arduino IDE on a system with limited RAM such as a low spec Raspberry Pi SBC.

This is done using Java's -Xmn, -Xms, -Xmx flags:

https://docs.oracle.com/en/java/javase/17/docs/specs/man/java.html#:~:text=to%20switch%20off.-,-Xmn%20size,-Sets%20the%20initial

If you want to experiment with temporarily setting various values without having to edit the arduino script file, you can set the special JAVA_TOOL_OPTIONS environment variable to the desired flags in your shell terminal before invoking the arduino script.

For example, if you wanted to set the maximum heap size to 2 MB (which is obviously a ridiculous thing to do because the IDE will need far more than that, but it's just a silly example):

$ export JAVA_TOOL_OPTIONS="-Xmx2M"

$ ./arduino

Picked up JAVA_TOOL_OPTIONS: -Xmx2M
Set log4j store directory /home/per/.arduino15
java.lang.OutOfMemoryError: GC overhead limit exceeded
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"

The environment variable will only be set for the duration of your terminal session, so once you have found the right heap size configuration, you probably don't want to have to set the environment variable over and over again each time you want to run the IDE. You can then add the flags to the arduino script.

I recommend appending them to the JAVA_OPTIONS array since that is the mechanism that was established in the script for this purpose.

For example, if you wanted to add the -Xmx2M flag (again, a silly example) to the java command, you would add this line to the script:

JAVA_OPTIONS+=("-Xmx2M")

above this line in the script:

"$JAVA" "${JAVA_OPTIONS[@]}" processing.app.Base "$@"

Wow. Thank you for taking the time to help me.
I did a search of any file on my Raspberry Pi which has the words "JAVA_OPTIONS" because I figure that would be the file I would add the JAVA_OPTIONS+=("-Xmx2M")
I tried both 2M and 1G - I don't see any difference.
But the good news is, it only gives me the Java Heap Space error after the first compile. After that, I can stay in the Arduino IDE without any errors.

That is odd. The reason I used 2M is because this should prove whether or not the flag is having an effect since the IDE can't start up if you set the maximum heap to such an insufficient value.

You can see that it failed to start in the output I shared in my previous reply:

$ ./arduino

Picked up JAVA_TOOL_OPTIONS: -Xmx2M
Set log4j store directory /home/per/.arduino15
java.lang.OutOfMemoryError: GC overhead limit exceeded
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"

That output was from when I was using the JAVA_TOOL_OPTIONS environment variable, but the same error also happens if I add that line to the arduino script file instead.

If I use

whereis arduino

on my Pi4 I get the following entries:

/usr/bin/arduino
/usr/local/bin/arduino
/usr/share/arduino
/usr/share/man/man1/arduino.1.gz

The first two entries are bash scripts.
The third entry points to the directory.
The fourth entry points to a manual page.

In my installation only the file in /usr/bin contains this line

which has to be replaced by the line as mentioned above.

If the file you found initially did not have the "java" line as above it is quite likely not the right file to change ...

I wonder if I can find another way to install it. I could then uninstall and reinstall to see if it fixes everything. The installation I used came for aurdunio.cc but I have read other people use other installs.

The manual installation from the Arduino Website is recommended as you'll get only a very(!) old version (at the moment 1.0.5) when you use "sudo apt-get install arduino".

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.