Sub-builds (antcall, subant) load a task each time the task is defined, but do not release it when the sub-build project completes. It would be best if the sub-build would recognize the task is already loaded, just like it does when the task is loaded within the same project using loaderref. If it is not feasible to re-use the task in this scenario, then it should be released to avoid sucking up all the available memory very quickly. I think this is only a problem with recent (> 1.5.8) releases of Groovy, since it requires so much PermGen. You can't give it enough anymore. The attached script runs out of memory in about 34 iterations of defining the groovy task within an antcall. It can be run as follows, where 3rdparty_libdir is the folder that contains the jars needed for the groovy task: ant -f GroovyMem.xml -Diterations=100 -D3rdparty_libdir=\3rdPartyJars\lib Note: The script uses AntContrib to iterate. http://marc.info/?l=ant-user&m=126970939205980&w=2
Created attachment 25209 [details] Analysis Script Demonstrates memory bug with: ant -f GroovyMem.xml -Diterations=100 -D3rdparty_libdir=\3rdPartyJars\lib
I ran into a similar problem. It appears that <taskdef> creates a new classloader every time (makes sense), but uses the J2EE delegation model and doesn't tie that classloader to the task/project that created it (doesn't make sense to me, but there might be a reason). So the classes never get GC'd. A longer writeup is on blog.kdgregory.com, today's date. There is a work-around: use Groovy via antlib, just like you're already doing with ant-contrib. Change your <project> element like this: <project name="GroovyMem" default="all" xmlns:antc="antlib:net.sf.antcontrib" xmlns:groovy="antlib:org.codehaus.groovy"> Then delete all of the <taskdef>s, and refer to the Groovy tasks using the namespace prefix: <target name="run_groovy"> <groovy:groovy> // do nothing </groovy:groovy> </target> Note that you will have to add Groovy to Ant's runtime classpath. My preferred way to do this is with the "-lib" command-line option.