title: Memory leak with PowerMock on Jenkins
body: <p>I think I'm getting memory leaks when using Jenkins to execute my unit tests. If I try to execute more than ~60 unit tests I start to get most tests failing with <code>java.lang.OutOfMemoryError: PermGen space</code>. Often, but not always, the stack trace seems to start in or near <code>org.powermock.core.classloader.MockClassLoader</code>, although it's not consistent. the The maven surefire plugin configuration is pretty straightforward:</p>
  
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
      &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
      &lt;version&gt;2.18&lt;/version&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;phase&gt;test&lt;/phase&gt;
              &lt;configuration&gt;
                  &lt;reuseForks&gt;false&lt;/reuseForks&gt;
                  &lt;argLine&gt;-XX:PermSize=512m -XX:MaxPermSize=1024m&lt;/argLine&gt;
              &lt;/configuration&gt;
          &lt;/execution&gt;
      &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>In Jenkins, MAVEN_OPTS is also set to <code>-XX:MaxPermSize=1024m</code>.</p>
  
  <p>I saw some documents suggesting it might be related to the fact that I was using an older version of powermock, so I upgraded to 1.6.0, but I am still experiencing this error.</p>
  
  <p>I can't reproduce the problem locally, it only seems to happen on the Jenkins server.</p>
  
  <p>I'm not sure how to reliably resolve this: limiting the number of tests cases that execute seems to work OK, but I have 150+ test cases to execute and running batches of 50 tests at a time on the server does not seem like a very good solution. I might be able to give it a bit more memory but it seems like it already has enough, and I don't think surefire needs that much memory when it runs locally. There might be a way to play around with some of the other surefire settings, but I'm not sure which ones I'd need to adjust, or how. Has anyone else every seen this, or have a suggestion for how to resolve it?</p>
  
  <hr>
  
  <p>This might be relevant: The development environment is IBM's RAD, and the workspace is launched with the option <code>-Xgcpolicy:gencon</code>, which as far as I can tell is specific to IBM's implementation of the JVM. Might this be the reason that the unit tests run fine when I run maven from RAD, but not from Jenkins? If so, what would be an equivalent option for the standard (Oracle) JVM, which Jenkins is using?</p>