I have read that Perm gen (or Permanent Generation) space is not garbage collected. However, in CMS collection I can see some classes unloading in my GC log. So is perm gen garbage collected during full collection or CMS collection?
-
Possible duplicate of http://stackoverflow.com/questions/88235/how-to-deal-with-java-lang-outofmemoryerror-permgen-space-error ? Anyway check that thread it will help for sure. – Sagar V Sep 26 '10 at 03:18
-
1no its not duplicate at all. This is a concept question asks for Yes/No answer, not a question seeking solution for an error. – YudhiWidyatama May 24 '12 at 06:03
2 Answers
The PermGen is garbage collected like the other parts of the heap.
The thing to note here is that the PermGen contains meta-data of the classes and the objects i.e. pointers into the rest of the heap where the objects are allocated. The PermGen also contains Class-loaders which have to be manually destroyed at the end of their use else they stay in memory and also keep holding references to their objects on the heap. The "Presenting the Permanent Generation" article by Jon Masamitsu on the Sun / Oracle blog site might help you.
-
2
-
4I've inlined the title and author so that people can find it if the link breaks again. – Stephen C Feb 12 '13 at 09:56
-
2
-
People are always mess up with native heap and java heap. PermGen is in native heap within java process. I think by using the term heap they sometimes mean java and native heap. – Rostislav V Aug 08 '17 at 13:07
-
In current generation JVMs, permgen is indeed collected like other parts of the heap. The visualgc page states that it is collected together with the old generation.
In older JVMs this was apparently not always so. For instance, in Java 5 the CMS collector apparently did not collect permGen by default: you could enable it with -XX:+CMSPermGenSweepingEnabled
. I also recall hearing that some really old JVMs did not implement permgen collection at all, though I cannot find a reliable source for this ... ermm ... "factoid".
The other point, is that a lot of people have incorrectly attributed "OutOfMemoryError : permgen" exceptions to permgen not being collected at all. The reality is different. The most common cause of these OOME's is an insidious kind of storage leak that manifests when you hot-load code into an executing JVM. The leak occurs because when an instance of some old class that has been replaced remains reachable. This causes the object's class to be reachable, which causes the classes classloader to be reachable, which causes all of the old classes to be reachable, together with their code objects, their string literals, and their static frames and static. A lot of these leaked objects live in permgen space.
UPDATE
As of Java 8, permgen no longer exists: PermGen elimination in JDK 8