6

When running my unit tests in Maven on windows i'm getting an OutOfMemory exception. I tried to add -XX:-HeapDumpOnOutOfMemoryError option to the surefire argLine, but no dump file is generated. I also tried to add the same thing to MAVEN_OPTS, but still nothing, I simply get an OutOfMemory exception and the process hangs until I manually kill it.

My pom is as follows:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>                    
        <testFailureIgnore>false</testFailureIgnore>
        <argLine>-Xms512m -Xmx512m -XX:PermSize=256m -XX:-HeapDumpOnOutOfMemoryError</argLine>
        <forkMode>once</forkMode>            
    </configuration>
</plugin>

MAVEN_OPTS:

set MAVEN_OPTS=-XX:-HeapDumpOnOutOfMemoryError

Do you have any idea why no dump file is generated?

dhable
  • 2,879
  • 26
  • 35
Koby
  • 605
  • 5
  • 11

4 Answers4

5

You're using "-" to disable the option. Use "+" to enable it:

<argLine>... -XX:+HeapDumpOnOutOfMemoryError</argLine>
                 ^ 
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
2

Try this:

set MAVEN_OPTS="-Dmaven.surefire.debug=\"-XX:-HeapDumpOnOutOfMemoryError\""
Brian Topping
  • 3,235
  • 28
  • 33
  • Still nothing. I don't see any output. I managed to find the memory leak by connecting using a profiler, so thanks anyway for your response. – Koby Jan 06 '11 at 08:42
1

Your memory leak might just be fixed, see http://jira.codehaus.org/browse/SUREFIRE-495. You may want to try surefire 2.7.1 or newer.

krosenvold
  • 75,535
  • 32
  • 152
  • 208
  • Thanks for you reply, but my problem isn't related to surefire. I use spring in my tests and I have different application contexts for the same beans over and over again. Because spring caches application contexts for performance reasons none for them got destroyed and I get the OutOfMemory error. The fix is to change my tests to use the same contexts instead of duplicating them in different contexts. – Koby Jan 16 '11 at 06:06
0

I think you forget the path :

    <argLine>-Xms512m -Xmx512m -XX:PermSize=256m -XX:-HeapDumpOnOutOfMemoryError  -XX:HeapDumpPath=/tmp</argLine>

with this argument :

     -XX:HeapDumpPath=/tmp
twillouer
  • 1,149
  • 9
  • 14
  • 1
    This is not necessary. Heap dump is created by default in project directory (I launch Maven via Netbeans). When would it be necessary? When would the current directory be different (and non-writeable)? – Aleksandr Dubinsky Jun 23 '17 at 07:42