title: sbt.Keys.fork in Test := true => Out of memory permgen space
body: <p>I own a Play 2.2.X application.</p>
  
  <p>I was running a suite of specs using Specs2 that ended up to an <strong>Out Of Memory regarding permgen space</strong>.</p>
  
  <p>Then I just placed this setting in my <code>Build.scala</code>:</p>
  
  <pre><code>sbt.Keys.fork in Test := false
  </code></pre>
  
  <p><strong>and it works now like a charm</strong>.</p>
  
  <p>According to some documentations, Play 2.X forks test by default in order to prevent memory leaks but I really observe the exact contrary. </p>
  
  <p>What could be the reason(s) for observing permgen issues when forking tests? I just don't figure it out.</p>
  
  <p><strong>UPDATE --------------</strong>
  With this configuration:</p>
  
  <pre><code>parallelExecution in Test := false,
  javaOptions in (Test,run) ++= Seq("-Xms512M", "-Xmx2048M", "-XX:MaxPermSize=2048M", "-XX:+CMSClassUnloadingEnabled")
  </code></pre>
  
  <p>Here's the error I obtain when forking is enabled:</p>
  
  <pre><code>Uncaught exception when running htmlreporting.AllSpecs: java.lang.OutOfMemoryError: PermGen space
  sbt.ForkMain$ForkError: PermGen space
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
      at scala.collection.parallel.immutable.LazyParVectorCombiner.result(ParVector.scala:129)
      at scala.collection.parallel.immutable.LazyParVectorCombiner.result(ParVector.scala:105)
      at scala.collection.Parallelizable$class.par(Parallelizable.scala:42)
      at scala.collection.AbstractTraversable.par(Traversable.scala:105)
      at org.specs2.reporter.AllExporting$$anonfun$export$1$$anonfun$2.apply(AllExporting.scala:28)
      at org.specs2.reporter.AllExporting$$anonfun$export$1$$anonfun$2.apply(AllExporting.scala:27)
      at scalaz.syntax.IdOps$class.$bar$greater(IdOps.scala:15)
      at scalaz.syntax.ToIdOps$$anon$1.$bar$greater(IdOps.scala:82)
      at org.specs2.reporter.AllExporting$$anonfun$export$1.apply(AllExporting.scala:32)
      at org.specs2.reporter.AllExporting$$anonfun$export$1.apply(AllExporting.scala:24)
      at scalaz.syntax.IdOps$class.$bar$greater(IdOps.scala:15)
      at scalaz.syntax.ToIdOps$$anon$1.$bar$greater(IdOps.scala:82)
      at org.specs2.reporter.AllExporting$class.report(AllExporting.scala:17)
      at org.specs2.reporter.SbtConsoleReporter.report(SbtReporter.scala:20)
      at org.specs2.runner.SbtRunner.org$specs2$runner$SbtRunner$$specificationRun(SbtRunner.scala:75)
      at org.specs2.runner.SbtRunner$$anonfun$newTask$1$$anon$5.execute(SbtRunner.scala:59)
      at sbt.ForkMain$Run.runTest(ForkMain.java:239)
      at sbt.ForkMain$Run.runTestSafe(ForkMain.java:211)
      at sbt.ForkMain$Run.runTests(ForkMain.java:187)
      at sbt.ForkMain$Run.run(ForkMain.java:251)
  </code></pre>
  
  <p>That works well when my conf becomes:</p>
  
  <pre><code>    parallelExecution in Test := false,
      sbt.Keys.fork in Test := false,  //here's the important setting
      javaOptions in (Test,run) ++= Seq("-Xms512M", "-Xmx2048M", "-XX:MaxPermSize=2048M", "-XX:+CMSClassUnloadingEnabled")
  </code></pre>