A Shoot at Permgen & Metaspace

1.java_logo

Once upon a time it used to be an excellent interview question. “What is Permgen in java ? “. Of course now also it hasn’t lost  its charm in stumping people. So, if you are lucky enough and bombard the interviewer with an inclined answer then you are fired with so many questions :-

  • What is Metaspace in Java ?
  • Why do we get java.lang.OutOfMemory in Permgen ?
  • What is the difference between Permgen and Metaspace ?
  • Is it true that Permgen is removed from java ? Why ?

Oh My God.. this Clunky fathomized piece of shit is just eating my head..That’s the gut feeling you will get exactly when you are little aware about Permgen and Metasapce. So, in this discussion our focus will be mainly on two people , one is Permgen and another is Metaspace.

What is Metaspace in Java ?
Permgen:- In short “Permgen” or “Permanent Generation” is the memory space java keeps aside to store the class declaration information which essentially includes: – class name and  fields
Method names
Constant pool information
Object arrays.
The Permgen is loaded during application start up. Permgen is a part of the heap memory. You can specify max Permgen Size with the jvm flag -XX:MaxPermGenSize=N. Where N is the size. If you don’t specify anything then platform specific default value will be used. Here is a table which says the default values and the max values

Now the question here is “Why do we get java.lang.OutOfMemoryError : Permgen”?
We usually get this error when the permgen heap space is running out of memory. It can be due to too many class loading or there could be some memory leak in the class loaders. So that the class loader objects are not garbage collected which will cause the permgen space to go out of memory.So if you get an OutOfMemoryException: PermGen you need to either resize the PermGen or you might have to analyze the class loaders. I feel finding the cause is a better approach so that we can atleast come to know the reason behind such errors.

Leave a Comment

Your email address will not be published. Required fields are marked *

Menu Title