Increase JVM heap size for Scala?

ScalaCommand LineJvmHeap Memory

Scala Problem Overview


I have a Scala data processing tool which is failing with a java.lang.OutOfMemoryError exception. The tool needs to make a couple passes over a large data file (the one I'm working on is over 700MB), so it would be convenient if the entire thing could be stored in memory.

I run the tool from the command line or from a Bash script using the "scala" runner. How do I increase the JVM heap size for this? I've tried passing -Xmx1024m, but it does not recognize this argument. I'm using a nightly build of Scala 2.8.0 (r18678).

Scala Solutions


Solution 1 - Scala

You can pass options to the JVM via -J. E.g.,

scala -J-Xmx2g ...

Solution 2 - Scala

The JAVA_OPTS environment variable is used to specify the options passed to the java command. See the Scala manpage for details.

Solution 3 - Scala

Based on Joe's suggestion, I looked at the scala program, which is a Bash script that calls java with various Scala specific arguments. It allows extra command line arguments to be passed to Java through the JAVA_OPTS environment variable. So you can increase the heap size like this:

JAVA_OPTS="-Xmx2g" scala classname arguments...

Solution 4 - Scala

Edit JAVA_OPTS.

Solution 5 - Scala

As a hack you can edit the scala/bin/scala file to edit the parameters for the java command. Not pretty.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJay ConrodView Question on Stackoverflow
Solution 1 - ScalaGeoffrey IrvingView Answer on Stackoverflow
Solution 2 - ScalaSynessoView Answer on Stackoverflow
Solution 3 - ScalaJay ConrodView Answer on Stackoverflow
Solution 4 - ScalaDaniel C. SobralView Answer on Stackoverflow
Solution 5 - ScalaJoeView Answer on Stackoverflow