#197 ForEach throws OutOfMemoryError

v1.0 (example)
open
nobody
logic (23)
5
2007-03-14
2007-03-14
Anonymous
No

I was assign to upgrade an old project pack configuration.In the project build script,the task "foreach" was called many times(in some loops),and it went down at a un-certain time with a java.lang.OutOfMemoryError.I tried to set a eviroment variable "ANT_OPTS=-Xms512m -Xmx1024m" to increase ant's memory usage forcibly and modify class "ForEach"'s source code where it creates and executes tasks as follow,but the error point just went forward a little.I also try to trace the error,the result shows at the construtor of ForEach.class JVM throws the OutOfMemoryError.I hope you can help me out of this trouble,Thank you.
BTW: My machine is Intel pentium 4 3.0GHz Mem:512M*4 JDK:1.4.2_11
Modified ForEach.execute() code as here:
for (int i = 0; i < sz; i++) {
val = values.elementAt(i);
ct = createCallTarget();
p = ct.createParam();
p.setName(param);

if (val instanceof File)
p.setLocation((File) val);
else
p.setValue((String) val);

ct.execute();
System.gc();

//tasks.addElement(ct);
}

/* if (parallel && maxThreads > 1) {
executeParallel(tasks);
} else {
executeSequential(tasks);
}*/

Discussion