Coldfusion TemplateClassLoader hold on to class loader instances?
I have a "OutOfMemoryError: PermGen space" erro开发者_如何学运维r 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?
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/
精彩评论