Tuesday, July 8, 2014

Garbage Collection in PermGen

This article tries to answer below questions:
  • Will garbage collection happen in PermGen in Java? 
  • What parameters control this behavior?  
  • How to tune PermGen size?


1. Firstly we need to understand the minor GC and major GC concept as shown below.
When the young generation fills up, a young generation collection (sometimes referred to as a minor collection) of just that generation is performed. When the old or permanent generation fills up, what is known as a full collection (sometimes referred to as a major collection) is typically done. That is, all generations are collected. Commonly, the young generation is collected first, using the collection algorithm designed specifically for that generation, because it is usually the most efficient algorithm for identifying garbage in the young generation. Then what is referred to below as the old generation collection algorithm for a given collector is run on both the old and permanent generations. If compaction occurs, each generation is compacted separately.
So the answer is yes, GC can happen in PermGen and it is counted as major/full GC.
We can use "jstat" to monitor the GC activity.

2. It depends on JDK versions.
In JDK before Java SE 6 Update 3 or earlier, "-XX:+CMSPermGenSweepingEnabled" is used to enable GC in PermGen. By default, GC will never happen in PermGen.

In JDK 7, "-XX:+CMSPermGenSweepingEnabled" is no longer used because GC by default will happen in PermGen. However another parameter "-XX:+CMSClassUnloadingEnabled" is introduced to tell the PermGen GC sweep to take action on class objects. By default, class objects get an exemption, even when the PermGen space is being visited during a garabage collection.

In JDK 8, PermGen no longer exists.

3. -Xmx (the maximum heap size) does NOT include the PermGen.
-XX:MaxPermSize controls the maximum memory used by the permanent generation.
-XX:PermSize controls the initial memory used by the permanent generation.


  1. I really appreciate the kind of topics you post here. Thanks for sharing us a great information that is actually helpful. Good day!
    trash removal nyc

  2. On the off chance that you hang on - the adversary's weight may startle you as well. In self-protection class, we for the most part show the understudy to clutch the wrist just and catch up with some stepping and kicking to the head. wisp broom

  3. This comment has been removed by the author.

  4. I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people. kitchen trash can

  5. GET IT DONE is an experienced, professional, fast and courteous, full-service Junk Removal company Junk Removal Ogden


Popular Posts