Wednesday, April 25, 2012

PermGen Out Of Memory Errors on Maven test

So we have some pretty intense projects that need a lot of memory to run. We added some VM arguments to give our tests more memory, something along the lines of -Xms512m -Xmx1024m -XX:MaxPermSize=512m we're still getting PermGen out of memory errors.

I wasn't sure how much memory we were actually using during the tests so I was able to connect to our maven instance by adding the following to the command:

As I monitored the test we never got above 20Mb of PermGen so what gives?

As I scoured the web I cam across a few blogs, such as this one that describe that when the surefire plugin creates a fork to run a test that those memory arguments you gave don't get passed along.

In order to make sure the surefire uses the right memory args you need to specify them using the argLine element, like so:

Another good option that I saw, but can't find again, was to use a variable as a place holder in your argLine: And then pass it in your command like mvn test -Dmaven.test.argline='-Xms512m-Xmx1024m-XX:MaxPermSize=512m'.


  1. Thanks! Now all my tests run!

  2. This solved my problem with permGen too. Thanks

  3. Hi, the tag is argLine with upper L! Thanks for the solution.