What is PermGen?
The permanent Generation is part of your heap space that is actually used to store meta-data information for the classes created by users and prior to Java 7, it is also used to store interned Strings (interned strings – used to remove String duplicates by internalizing them to reduce memory consumption). As of Java 7, intern strings also moved as a part of heap space to make the more space available in Permanent Generation.
As a Java developer I am sure that all of us have seen this very famous OutOfMemoryError: PermGen Space error and it happens when Permanent Generation space is full , which is mostly happened by memory leak. Most common reason for a memory leak is when loaded classes and class loaders are not garbage collected when they are undeployed.
Metaspace in Java8:
PermGen has been completely replaced by MetaSpace in Java8, a native memory to store class meta-data information and that grows automatically. Good thing is that as of Java 8, we will never see OutOfMemoryError : PermGen Space error , moreover we won’t have to tune PermSize and MaxPermSize arguments at the start-up of application. On the contrary these two jvm arguments are now replaced by MetaspaceSize and MaxMetaspaceSize. These two new flags gives us the flexibility to change the value for default size of metaspace and to change the maximum value that this metaspace can take.
MetaspaceSize : This flag comes into the picture when you want to change the default size of your native memory that jvm can use. Use this flag only when you are sure that your application is going to need more memory than what is provided by default otherwise you will end up in suppressing some of the Garbage Collectors that were supposed to run in the default configuration.
MaxMetaspaceSize : This flag provides you flexibility to set the maximum size that you want to allocate for metaspace. You might want to do this to control the space used by your applications (multiple) running on a server or in a case of memory leak so that it won’t use all of available space in native memory. Now in the case when your native memory is fully and your application still needs more space in that case you will see a new error message : java.lang.OutOfMemoryError: Metadata space.
Overall if we see there is not a much difference between PermGen and Metaspace in Java8 except the new flags and the error message that we have seen earlier. Only advantage now you will have more space in the heap, but on the other side we don’t have any tool with which we can analyze this meta-data information as compared to the tools available e.g.jconsole ,HeapAnalyzer etc for analyzing heap.
Note : Java8 has been already officially released on 18th March 2014.
Disclaimer : All the above used images belong to their respective owners and used only for reference.
Latest posts by Saurabh Jain (see all)
- java.lang.IncompatibleClassChangeError: Found interface org.apache.hadoop.mapreduce.TaskInputOutputContext, but class was expected - August 8, 2014
- org.datanucleus.store.rdbms.exceptions.MappedDatastoreException: INSERT INTO “TABLE_PARAMS” – Hive with Kite Morphlines - July 17, 2014
- java.io.IOException: can not read class parquet.format.PageHeader: null – Hive - July 12, 2014