4

Does garbage collection occurs in PERM Area of Java Heap ?

PERM area is used to store meta data about classes, methods, variable etc... also String Pool created in PERM area of heap so I believe garbage collection does not occur here?

edgarmtze
  • 24,683
  • 80
  • 235
  • 386
  • 1
    Duplicate of http://stackoverflow.com/questions/3796427/in-java-does-permamnent-generation-space-garbage-collected – CoolBeans Mar 22 '11 at 04:24
  • Good question - I'd assume those objects can be collected when their parent classloader can be discarded, but not posting as an 'answer' since I'm guessing a bit . – Steve B. Mar 22 '11 at 04:25
  • @Steve B - It's same as other elements on the heap. So it gets garbage collected eventually. – CoolBeans Mar 22 '11 at 04:26

2 Answers2

3

With each deployment, new class objects get placed into the PermGen and thus occupy an ever increasing amount of space. Regardless of how large you make the PermGen space, it will inevitably top out after enough deployments. What you need to do is take measures to flush the PermGen so that you can stabilize its size. There are two JVM flags which handle this cleaning:

-XX:+CMSPermGenSweepingEnabled

This setting includes the PermGen in a garbage collection run. By default, the PermGen space is never included in garbage collection (and thus grows without bounds).

-XX:+CMSClassUnloadingEnabled

This setting tells the PermGen garbage collection 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.

Dead Programmer
  • 12,427
  • 23
  • 80
  • 112
0

I believe that theoretically if a class loader is garbage collected the classes that were loaded by that classloader can be garbage collected. These classes would be in the Permanent generation.

MeBigFatGuy
  • 28,272
  • 7
  • 61
  • 66