Friday, March 12, 2010

Out of Memory Exceptions in Ant

While trying to get some new build machines cooking, a colleague of mind forced me to notice that Java 1.6 on Windows must default it’s heap size to 64 megs. When running an Ant job, he was getting and Out of Memory Exception when trying to compile JUnit reports via the JUnitReport Task.

I figured out the default heap size by opening JConsol and checking Max setting on the Memory Tab. Sure enough, without any Max Setting it was 64m.

What got this whole thing confused was that we were setting a larger heap (1.6gig) on the JUnit execution. That is, when JUnit forked out for its own VM to run on, it used 1.6 gigs which turns out to be more than enough. However, the Ant process was running at 64m (the default remember) and giving us fits when Ant’s JUnitReport, which does not fork itself, was trying to compile the HTML reports.

To fix this, we simply upped Ant’s Max Heap Size to something larger (e.g. –Xmx512m) by setting ANT_OPTS=–Xmx512m as an Environment variable on the server. (As a side note, remember you need to refresh the environment of any tooling needing to use this new variable. Examples are recycling a process like Team Build or closing and restarting your command prompt). Once we did this all was better.

Free coffee is coming my way!

No comments: