Skip to content
Advertisement

Is perm gen part of heap?

I started reading things about java, jvm and so. But when it comes to perm gen memory i keep getting different answers. I really do not get it, and get confused more and more, because there are many explanations that are different. So, is perm gen part of heap or it is not ?

Advertisement

Answer

First of all, modern JVMs do not have a PermGen.

The PermGen was dropped entirely in Java 8. So there is really little point in learning about it. All versions of Java prior to Java 8 are end-of-life, and you should have migrated your code a long time ago. And if you are having problems with PermGen in a legacy application on a pre Java 8 JVM, that is another reason to port it1.

The (Java 7 and earlier) PermGen is described by different people / sources as either:

  • a separate heap, or
  • a separate region of “the heap”.

Both of these descriptions are true, depending on your perspective. The facts that are not open to debate are:

  • The PermGen heap (or region) was sized separately from the rest of the “regular” heap. Thus there was a risk of running out of PermGen space even there was regular heap space available.
  • The PermGen was garbage collected … with one or two exceptions. The thing was that it was garbage collected infrequently, on the assumption that there would be minimal garbage in the PermGen to actually collect.

The PermGen was used for class metadata, and (prior to Java 7) for the string pool used for string objects that corresponded to compile-time string constants (e.g. literals). In Java 7, the string pool was moved to the regular heap.


1 – OK. Sometimes, upgrading is not possible; e.g. due to legacy hardware, or customers who refuse to do the sensible thing. But for those cases, you should avoid the kind of new code development that may introduce new PermGen problems. And you should eschew the kind of dev/test/deploy practices (e.g. hotloading) that can lead to PermGen leaks.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement