Thursday, October 12, 2017

What is Permanent Generation in java memory model?

The permanent generation is special because it holds meta-data describing user classes (classes that are not part of the Java language). Examples of such meta-data are objects describing classes and methods and they are stored in the Permanent Generation. Applications with large code-base can quickly fill up this segment of the heap which will cause java.lang.OutOfMemoryError: PermGen

Permanent Generation or “Perm Gen” contains the application metadata required by the JVM to describe the classes and methods used in the application. Note that Perm Gen is not part of Java Heap memory.
Perm Gen is populated by JVM at runtime based on the classes used by the application. Perm Gen also contains Java SE library classes and methods. Perm Gen objects are garbage collected in a full garbage collection.

a)    Contains application metadata required by JVM.
b)    Method Area – part of space in Perm Gen and used to store class structure (runtime constants and static variables) and code for methods and constructors.
c)     Memory Pool- Pool of immutable objects.
d)   Runtime Constant Pool -It contains class runtime constants and static methods. Runtime constant pool is the part of method area.
e)     Stack Memory - Java Stack memory is used for execution of a thread. They contain method specific values that are short-lived and references to other objects in the heap that are getting referred from the method. 
When stack memory is full, Java runtime throws java.lang.StackOverFlowError whereas if heap memory is full, it throws java.lang.OutOfMemoryError: Java Heap Space error.

No comments:

Post a Comment