1

I have a "OutOfMemoryError: PermGen space" error on my CF 8 server. In my app 1000 templates were loaded into the same local variable (for testing purpose), so once the next one is loaded, the prior one should be available for GC - but this does not happen. I got a memory dump and looked at it with jhat. What I saw was it loads the thousand templates, each with it's own TemplateClassLoader instances. In the TemplateClassLoader it self there is a static reference to all TemplateClassLoader instances (again this is from the jhat). Probably because of this, the instances are hold in memory, so the class objects can not be GC in permgen.

This "holding on memory" only happens if I call a cfscript function in the template once is loaded. If I just load the template but not calling the function, the class objects are GCed and no OOM error occurs.

Any idea what's happening on the (appeared) static reference on the TemplateClassLoader?

1 Answer 1

2

I have that figured out. In the CF admin page Server Settings > Caching there is a field "Maximum number of cached templates". It controls how many templates should be in a LRU cache. If a template is in that cache, there is a strong reference to the java class object and can not be GCed. In my CF setup it uses a default value of 1024. This is why in my test the 1000 unique templates none get GCed.

There is a bit more info here: http://blogs.sanmathi.org/ashwin/2006/07/12/tangling-with-the-template-cache/

Sign up to request clarification or add additional context in comments.

1 Comment

I came across this looking for the reason why Eclipse MAT says that '3,421 instances of "coldfusion.runtime.TemplateClassLoader" occupy 242,105,472 bytes'. It would seem that this is the template cache. Thank you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.