Ant and OutOfMemoryError exceptions

C

Corey Yeatman

Hi,

I've hit a problem with ant throwing an OutOfMemoryError. I'll
describe what I'm doing and what I think is happening, and if anyone
can confirm this (or suggest an alternative) then that would be great.

What I'm doing is using an ant build file to run a large set of junit
tests automatically and capture the results. It compiles up my java
code-base, then scans the path looking for unit tests to run, and runs
them in groups (depending on the type of unit test and it's
requirements). I have written some custom ant-tasks to find and run
the tests, and these actually call other ant targets in the buildfile
to set up stuff and strip it down again (e.g., rebuild databases,
etc.) required by the tests as necessary. There are about 160 tests
to run.

I've found that after about 90-100 tests, it crashes with an
OutOfMemoryError. Some of the tests are complicated, but they
shouldn't require a massive amount of heap space. I've got the <junit>
target set with fork="yes", so it uses a different JVM to run the
actual tests, so something is sucking up the heap space allocated to
ant's JVM.

I did a bit of reading on the web, and someone mentioned that every
time ant calls another <ant> or <antcall> target and you haven't got
the inheritAll flag set to "false", it duplicates the entire
environment from the parent project, including taskdefs, references,
etc. and passes it to the new task. It also uses a new instance of
it's own internal ClassLoader to pull in taskdef classes, so these can
get loaded over and over again.

My custom task which runs a set of junit tests actually 'loops' within
the task code itself to run all of the tests in the group - and this
runs other ant tasks to do the work. Because it's looping this may
mean a garbage-collect will not free up the memory associated with all
of the sub-tasks until the unit-test-running task finishes, as it may
be hanging on to a reference somewhere.

Anyway ...

I've altered my build files to only pull in taskdef classes
immediately before it needs them, and have used the inheritAll="false"
flag on <ant> and <antcall> statements to stop it pulling in the
entire environment (i.e., I'm passing params into the targets). This
seems to have helped immensely, and now the entire run works again -
BUT, it's still slowly chewing up some of the heap space allocated to
ant's JVM, so I'm not convinced I've fixed it yet (e.g., over the
space of 20 tests, it's gone from using about 10Mb of heap space to
54Mb). I'm really looking to nail this problem so that it doesn't
come back to haunt me in a few months.

Is anyone aware of this type of problem and/or what the correct
approach is to fixing it?

And before anyone suggests it - I've already pushed the heap size up
for ant's JVM using the -Xms and -Xmx flags to 768Mb (!!), but this
isn't helping. Pushing it even higher will just disguise the problem
and not actually solve it so I'm trying to figure out what's going on.


Thanks in advance for any help anyone can give me.


Regards,
Corey.
 
T

Tony Morris

Excuse me for not reading the entire post.
I stopped at this part:
" I have written some custom ant-tasks to find and run the tests"

So, why are you running a custom task, instead of the built-in (though
optional) <junit> task like everyone else?
If you have some valid and unforeseen reason, I believe I have used Ant
enough to make an educated guess that your custom task is the core of the
problem (since I have never seen your problem when using Ant conventionally,
or with my own custom tasks).
Provide the output of ant -v

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)
 
Joined
May 3, 2007
Messages
2
Reaction score
0
Faced the same issue

Hi Corey,

I have the same problem that you have mentioned. Only difference being, I have not written any custom ant tasks, also OOME happens sometimes but doesn't happen some other time. Looking at the windows task manager, I could see that when the error happens the Symantec Antivirus seems to be running some task (rtvscan.exe). But I am yet to ascertain this is linked to the OOME.

Strange ways of memory handling on windows I suppose..

Let me know if you found the cause/solution for this.

Regards
Shashi
Corey Yeatman said:
Hi,

I've hit a problem with ant throwing an OutOfMemoryError. I'll
describe what I'm doing and what I think is happening, and if anyone
can confirm this (or suggest an alternative) then that would be great.

.....


Regards,
Corey.
 
Joined
Mar 2, 2010
Messages
2
Reaction score
0
Increase your Java Heap size

I've read a couple places that you just need to increase your Java Heap size.

One post I read said this:

"Well a bit of Googling turned up that Ant looks for an environment variable called ANT_OPTS which is use to set Java parameters. Just set the environment variable and off you go. So I added the following to increase the heap size:

export ANT_OPTS=-Xmx256m

That sets the maximum heap size to 256 Megabytes. It solved my problem as the XSLT transform topped out at about 220Meg. So if you ever need to increase the size of the Ant JVM, now you know how."

We tried that on my co-workers machine and the build started working again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top