3

I know that in the JVM, the permgen area is used to store class definitions. In my Tomcat I see that the current memory usage of the permgen is near 100MB, it seems that it's just growing over time, even there's no one using the applications in Tomcat My questions are:

Is it true that the permgen is never garbage collected, I mean the memory used there keeps growing and growing?

When the permgem gets garbage collected?

What does mean "CMSPermGenSweepingEnabled" and "CMSClassUnloadingEnabled"?

My max size of permgem is 256 and I don't want to have an OutMemoryException next week.

Please only accurate and documented answers.

I use Tomcat 7, Java 7, I use a lot the parallel deployment tecnique and I do undeploys, redeploys several times a week. I never use the method intern() of Strings

Nestor Hernandez Loli
  • 1,412
  • 3
  • 21
  • 26
  • what version of tomcat are you using? – Claudiu Feb 19 '14 at 20:17
  • might be worth checking the things listed [in this document](https://plumbr.eu/blog/what-is-a-permgen-leak) – Claudiu Feb 19 '14 at 20:19
  • I too once encountered a permagen leak. Mine was while using xpath to query XML objects in a java application. The document builder was adding classes it made as it parsed the XML to the permagen. It would parse this XML every time it changed. Slow leak, but it did cause problems. – Mark W Feb 19 '14 at 20:23
  • Do applications often get {un,re}deployed? – fge Feb 19 '14 at 20:26
  • are you internalizing too many String objects ? – jmj Feb 19 '14 at 20:35
  • Since your PermGen occupancy is currently less than half of the maximum, the GC may simply not be triggered yet. – Marko Topolnik Feb 19 '14 at 20:37
  • The `CMS...` options pertain to the Concurrent Mark and Sweep collector, which is not on by default. In case it isn't, the operations implied by those settings happen as a matter of routine. – Marko Topolnik Feb 19 '14 at 20:40
  • @Marko Topolnik , please document your first comment: some links or books that support your statement – Nestor Hernandez Loli Feb 19 '14 at 21:12

1 Answers1

2

actually it's not true that Permgen does never get garbage collected. It contains the classes that where loaded by the application, and gets collected when classloaders get garbage collected, typically in redeployment scenarios.

You can use these JVM flags to see when classes are loaded into and unloaded from the permgen:

-XX:+TraceClassLoading -XX:+TraceClassUnloading

To see which classes are getting loaded, use this flag:

-verbose:class

If the application is reflection intensive, that can be a cause too, have a look at this answer, try to use visualvm to take heap dumps an look for classes named lie sun.reflect.GeneratedMethodAccessor11.

For the garbage collection flags refer to this answer, but the best bet to fix the permgen leak is to see what classes are being created and why using some tooling/logs.

Community
  • 1
  • 1
Angular University
  • 42,341
  • 15
  • 74
  • 81
  • It should be noted that, depending on who you ask and what version of the JVM you're talking about, "permgen" may include stuff that's allocated once at startup and had no possibility of being collected. Depending on the version of the JVM/collector this may be thrown in with class objects in "permgen" or may be treated physically or "morally" separately. – Hot Licks Feb 19 '14 at 21:43