Running out of memory in JUnit tests when run in the Ant Build Runner

My tests are failing due to an out of memory error (see below) when being executed within the TeamCity Agent Ant Build Runner but not when run from the command line.

I'm using TeamCity Professional Version 3.1.1 (build 6828)

The agent running the tests is the default agent installed on the same box as TeamCity server. There are 2 GB installed on the box and aprox one GB available in memory before running any tests.

The memory error is as follows:
java.lang.OutOfMemoryError: PermGen space

This error occurs just at the end of running the test target when executed by the TeamCity Agent Ant Build runner.

The test target builds out the domain and test classes and then executes two junit test batches each containing 110 and 12 tests respectively. The JVM is not forked in either case.

I've monitored the memory utilized while the tests are running and the memory utilization constantly grows from 1.02GB to 1.6 GB.

Note that if I run the same ant test target from the agent build work directory just using Ant then the build is successful and memory utilization is at most 900MB. It appears that the Ant Build runner is not releasing any resources.

1 comment
Comment actions Permalink

PermGen space contains loaded classes and interned strings, if there are too much of them you will see java.lang.OutOfMemoryError: PermGen space error. If you do not fork JVM for tests try to increase perm gen space for ant JVM: -XX:MaxPermSize=120m (this can be specified on build configuration page).

If you are using relatively new Java you can also pass the following argument to JVM: -XX:HeapDumpOnOutOfMemoryError (works for JDK 1.5.0_07). In this case when next time such error occurs hprof file should be created in the tests working directory on the agent. Please upload this file to our ftp server for investigation:

Pavel Sher


Please sign in to leave a comment.