I recently started work on an art project, and decided to use Ruby-Processing for it. For years I’ve used standard Processing in other projects and wanted to try out a variation. I’ve loved being able to use Ruby syntax and conventions, while retaining the simple Processing API.
I ran into a small snag at one point, though. I’d decided to generate a larger image, and suddenly my program was crashing with the error message:
java.lang.OutOfMemoryError: Java heap space (NativeException)
I was familiar enough with Java to know that the Java Virtual Machine [JVM] was being started with too little memory allocated and wasn’t able to handle the amount of processing I was asking for. But I was writing what felt like a plain Ruby script. Where did the JVM come into play, and how was it being initialized?
I know that Ruby-Processing uses JRuby to call into Java and run Processing. I was hoping I wouldn’t have to dig too deep into this relationship to make adjustments to the JVM startup settings.
Luckily I discovered that Jeremy Ashkenas [jashkenas], the creator of Ruby-Processing, posted a solution on the Processing bulletin board. The trick is to put a file named “java_args.txt” into your sketch’s data folder.
I had to create a new folder named “data” in the root directory of my project. In it I added the new java_args.txt file. The following settings worked for my needs:
-Xms528m -Xmx1024m
This was picked up the next time I ran my script and I was off and running.