Tomcat PermGen problem

A little side topic. Seems that every time i clean-build the project, triggering an autopublish and context reload, and after i ‘refresh’ the app in the browser with a button calling close() on application, Tomcat loads the app in memory, but it doesn’t clean the old, so each time i do this it goes up another 15MB. At about 112MB i get a PermGen error. How to fix this please? I mention i put these in the environment and it didn’t help:

-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -Xms512m -Xmx512m

EDIT: I upgraded to Tomcat 6.0.29, because 6.0.26 puts in some antileak code (that doesn’t seem to be doing much by itself in my case, as it fixed stuff for others, but it lets me know the following). Hope someone will keep an eye out to fix the memory leaks that this Tomcat detects.

This is fixable with a server restart, but it would be nice if the leaks wouldn’t be there too.

It is common for there to be permanent generation leaks when deploying a web application on a server. There are some very nice articles explaining this, including
this series
from Jevgeni Kabanov, one of the people behind JRebel. Also,
this interview
about Tomcat 7 leak protection explains common causes for such leaks.

Most developers just increase the permanent generation size (e.g. -XX:MaxPermSize=512m if you have plenty of memory) and then restart the server every now and then.

I put those setting everywhere, CATALINA_OPTS, JAVA_OPTS, tomcat doesn’t seem to pick it up, it always generates the PermGen error at ~111MB size of javaw.exe

Found some usefull posts for reference too:

It’s good that it shouldn’t cause any problems on production since a server restart fixed the hot deployment leak problems.