I've run load against my web application for the past few days, and I've noticed that "Current Classes Loaded" viewed via JMX monitoring is continually increasing. It will go up and then back down, but the average amount of classes loaded is increasing linearly with time. At the beginning of load, "Current Classes Loaded" was only a few thousand. Now, however, "Current Classes Loaded" has reached 130,000+.
Is this normal? I know that classes will fill up PermGen memory, but it's not definitive whether or not PermGen memory is leaking.
Used:
65,124 kbytes
Committed:
65,536 kbytes
Max:
65,536 kbytes
The used number moves between 62k and 65k, but I haven't noticed any catastrophic failure yet on the server. My question, then, is twofold.
First, is this normal? If it isn't, will this eventually cause Tomcat to crash?
i'm afraid there is no clear answer to your question. the most space in the permgen should be occupied by the classes of your application. it is possible your application is generating classes while it is running. then the described behaviour of your application is as expected. when your application is not generating classes on the fly, the number of loaded classes and amount of permgen should be more or less static.
when your application is creating to much classes you can get memory problems. you will then see
java.lang.OutOfMemoryError: PermGen space
messages in the tomcat log. you can test this by setting the perm gen explicitly with this parameter:-XX:MaxPermSize=
.you can also try this parameter:
-XX:+CMSClassUnloadingEnabled
with the cms garbage collector. when the number of loaded classes does not go down, you still have references from objects to these classes. this could be a sign you really have a memory leak. but you definitely have to know the running application to be sure. when this is the desired behavior of the application you can only increase the space for the perm gen. the size of the perm gen is additional to the size of the heap.here is a posting on stackoverflow which suggests a method to make clear what is the content of the permgen.