velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chenjian <chenj...@uvic.ca>
Subject out of memory error using VelocityEngine multiple instances
Date Thu, 09 Sep 2004 17:20:12 GMT
Hi,

I am profiling my velocity web application and it seems to me that after 
velocity completes the rendering, it leaves some objects behind. When running 
some complex templates with big objects, the memory goes up and never comes 
down even after velocity finishes parsing.

Therefore, I did some simple test, and here is a snippet of code I used:

for (int i = 0; i < 100; i++)
{
 StringWriter sw = new StringWriter();
 VelocityEngine ve = new VelocityEngine();
 ve.setProperty(FILE_RESOURCE_LOADER_PATH, ".");
 ve.init();
 ve.evaluate(ctx, sw, "vlog", str);
 System.out.println(sw.toString());
}

I passed in the template as a java String and used the evaluate method.

I got java.lang.OutOfMemoryError when profiling using JDK's hprof.

The hprof file snippet is as follows:

SITES BEGIN (ordered by live bytes) Thu Sep 09 10:07:01 2004
          percent          live          alloc'ed  stack class
 rank   self  accum     bytes objs     bytes  objs trace name
    1 19.93% 19.93%   9397200  573   9397200   573 300143 int[]
    2 19.90% 39.83%   9380800  572   9380800   572 300144 int[]
    3 18.96% 58.79%   8938000  545   9397200   573 300123 int[]
    4 18.96% 77.75%   8938000  545   9397200   573 300124 int[]
    5  9.98% 87.73%   4703184  573   4703184   573 300142 char[]
    6  9.49% 97.22%   4473360  545   4703184   573 300122 char[]
    7  0.51% 97.72%    238368  573    238368   573 300129 int[]
    8  0.43% 98.15%    201696  573    201696   573 300141 int[]
    9  0.28% 98.43%    132936  573    132936   573 300127 int[]
   10  0.28% 98.71%    132936  573    132936   573 300126 int[]
   11  0.28% 99.00%    132936  573    132936   573 300125 int[]
   12  0.23% 99.23%    109984 4676    109984  4676 300167 
org.apache.velocity.runtime.parser.node.Node[]
   13  0.22% 99.45%    105432  573    105432   573 300140 int[]
   14  0.15% 99.60%     68992 4312     68992  4312 300172 
org.apache.velocity.runtime.parser.node.Node[]
   15  0.08% 99.68%     40016    1     40016     1 300077 java.lang.String[]
   16  0.08% 99.77%     40016    1     40016     1 300076 java.lang.String[]
   17  0.08% 99.85%     37856   28     38752    56 300158 
org.apache.velocity.runtime.parser.node.Node[]
   18  0.07% 99.92%     32088  573     32088   573 300128 
org.apache.velocity.runtime.parser.Parser$JJCalls[]
   19  0.01% 99.93%      5376  224      5376   224 300188 
org.apache.velocity.runtime.parser.node.Node[]
SITES END

So, it seems that looping through multiple velocity engine instances leaves 
some velocity objects in the heap and not garbage collected. For example, 
org.apache.velocity.runtime.parser.node.Node[].

Could anyone help me to look into this? How can I make velocity engine run and 
go away cleanly without leaving any un-collected objects behind?

Thanks a lot,

Jian



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message