I am trying to run a program which takes a large amount of memory using the sbt "run" command and I seem to be running into the problem that the jvm seems to be getting a second -Xmx parameter from somewhere that overrides mine.
I am running the program via "sbt run".
Looking at the processes I can find the following:
/usr/bin/java -XX:MaxPermSize=256M -Xmx32G -Xms1024m -Xmx1024m -XX:ReservedCodeCacheSize=128m -jar /usr/local/Cellar/sbt/0.13.6/libexec/sbt-launch.jar run
My sbt file is as follows:
lazy val commonSettings = Seq(
organization := "edu.university",
version := "0.1.0",
scalaVersion := "2.10.2",
name := "Example",
javaOptions += "-Xmx32G"
)
If you would like to test it this is a piece of code I created that just fills memory.
package edu.university
import java.lang.Thread
import scala.collection.mutable.ArrayBuffer
object Main {
val arraySize = 10000
val nmws = 160000000 // no OOM
// val nmws = 180000000 // OOM
val r = scala.util.Random
def main(args: Array[String]): Unit = {
println("hi")
val ab = new ArrayBuffer[Memwaster](nmws)
ab.transform { a => new Memwaster(r.nextInt) }
println("done")
Thread.sleep(20000)
}
}
class Memwaster(foo: Int)
Running with the larger nmws value will use a little over 1G of memory then throw an out of memory error.