You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Daniel Rall <dl...@finemaltcoding.com> on 2002/04/02 23:47:54 UTC
Re: Anakia Memory Leak error in velocity version 1.2
Rajesh Bahtia <rb...@openlatitude.com> writes:
> When we have a very large build.xml that has many AnakiaTask tags , the
> Anakia throws an Out Of Memory exception.When we profiled to determine the
> cause we saw that the velocity engine member variable (ve) in
> AnakiaTask.java was been created everytime and it had instances to the DOM
> document which resulted in the lots of memory been utilised and ultimately
> caused the "Out Of Memory" error.
>
> My colleague Mitch Christensen (Principal Architecht) has fixed the execute
> function to make the variable ready for garbage collection and this has
> impoved the performance tremendoulsy.and no longer we the "Out Of Memory"
> error.
>
> I am including the code here and hope that in gets incorporated into the
> velocity version 1.3.
Not sure if this was addressed. Are you running with caching turned
on? If so, turning it off ought to obviate the need for this patch.
Here's a diff showing the changes against CVS HEAD:
--- /home/dlr/src/velocity/src/java/org/apache/velocity/anakia/AnakiaTask.java Mon Nov 12 13:38:09 2001
+++ /home/dlr/AnakiaTask.java Tue Apr 2 13:41:38 2002
@@ -94,7 +94,7 @@
*
* @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
* @author <a href="mailto:szegedia@freemail.hu">Attila Szegedi</a>
- * @version $Id: AnakiaTask.java,v 1.33 2001/11/09 00:12:56 geirm Exp $
+ * @version $Id: AnakiaTask.java,v 1.1.1.1 2002/03/23 17:45:49 mchriste Exp $
*/
public class AnakiaTask extends MatchingTask
{
@@ -246,6 +246,9 @@
String[] list;
String[] dirs;
+ if(ve == null)
+ ve = new VelocityEngine() ;
+
if (baseDir == null)
{
baseDir = project.resolveFile(".");
@@ -332,6 +335,9 @@
{
process( baseDir, list[i], destDir, projectDocument );
}
+
+ // allow GC of the Velocity Engine
+ ve = null ;
}
/**
@@ -391,6 +397,7 @@
context.put ("xpath", new XPathTool() );
context.put ("escape", new Escape() );
context.put ("date", new java.util.Date() );
+ context.put ("xmlFilePath", xmlFile );
// only put this into the context if it exists.
if (projectDocument != null)
@@ -413,9 +420,9 @@
catch (JDOMException e)
{
if (outFile != null ) outFile.delete();
- if (e.getCause() != null)
+ if (e.getRootCause() != null)
{
- Throwable rootCause = e.getCause();
+ Throwable rootCause = e.getRootCause();
if (rootCause instanceof SAXParseException)
{
System.out.println("");
@@ -507,3 +514,4 @@
}
}
}
+
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>