Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Out of Memory Error Using SBT When Executing Lift Project

I am using SBT 0.7.7. When I make a change to my Lift project and re-compile via:

  1. jetty-stop
  2. compile
  3. jetty-run

I get the following error:

Error during sbt execution: java.lang.OutOfMemoryError: PermGen space

I have the following defined inside /opt/local/bin/sbt-0.7:

# Is the location of the SBT launcher JAR file.
LAUNCHJAR="/opt/local/share/sbt-0.7/sbt-launch-0.7.7.jar"

# Ensure enough heap space is created for SBT.
if [ -z "$JAVA_OPTS" ]; then
JAVA_OPTS="-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M"
fi

# Assume java is already in the shell path.
exec java $JAVA_OPTS -jar "$LAUNCHJAR" "$@"
like image 296
Hahnemann Avatar asked Jan 06 '12 00:01

Hahnemann


People also ask

How can I increase my SBT memory?

Increase Memory for sbt and Maven It is possible to start Maven and sbt with increased memory. We recommend you increase the Maximum Metaspace size and the Thread Stack size. These values can be set using -Xss2M -XX:MaxMetaspaceSize=1024M . The exact values may depend on your hardware and your code base.

How do I fix out of memory heap space in Java?

OutOfMemoryError: Java heap space. 1) An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options "-Xmx512M", this will immediately solve your OutOfMemoryError.

What is OutOfMemoryError Java heap space?

OutOfMemoryError is a runtime error in Java which occurs when the Java Virtual Machine (JVM) is unable to allocate an object due to insufficient space in the Java heap. The Java Garbage Collector (GC) cannot free up the space required for a new object, which causes a java. lang.

What is OutOfMemoryError?

OutOfMemoryError exception. Usually, this error is thrown when there is insufficient space to allocate an object in the Java heap. In this case, The garbage collector cannot make space available to accommodate a new object, and the heap cannot be expanded further.


Video Answer


2 Answers

The PermGen is just one of many spaces that as a whole make up the Heap. You could increase the entire heap until the portion that is allocated is big enough for your needs or you could simply increase the allocation toward the PermGen space. In order to do that latter, use

For sbt 0.12.0

export SBT_OPTS=-XX:MaxPermSize=256m

It would be best to put this in your .bash_profile (assuming you are using bash)

For sbt 0.7

In your case increase the -XX:MaxPermSize to something more than 256m. Keeping in mind that needing more than 256m suggests that there may be other issues.

like image 67
juice Avatar answered Oct 12 '22 15:10

juice


You need to allow java to allocate more memory.

# You may need more or less depending on your project.
export SBT_OPTS=-Xmx1024M

You might revisit some of those other memory settings as well. I'm running SBT 0.11.2, and I have nothing but Xmx specified.

As an aside, I'd be surprised if you actually have any GC issues during a compile. Changing the GC collection strategy more relevant for longer running processes.

like image 29
Chewbarkla Avatar answered Oct 12 '22 16:10

Chewbarkla