Search Tutorials

Java - MetaSpace vs PermGenSpace | JavaInUse

Java - Metaspace vs PermGen space

In previous chapter we saw JVM memory model till java 7 and before. In this chapter we look at JVM memory model for Java 8. It is as follows-


Java Metaspace:

So what is Metaspace and how is it different from PermgenSpace.
With JDK8, the permGen Space has been removed. So where will the metadata information be stored now? This metadata is now stored in a native memory are called as "MetaSpace". This memory is not a contiguous Java Heap memory. It allows for improvements over PermGen space in Garbage collection, auto tuning, concurrent de-allocation of metadata.

Difference between PermGen space and MetaSpace.
PermGen Space MetaSpace
PermGen always has a fixed maximum size. Metaspace by default auto increases its size depending on the underlying OS.
Contiguous Java Heap Memory Native Memory(provided by underlying OS)
Max size can be set using XX:MaxPermSize Max size can be set using XX:MetaspaceSize
Comparatively ineffiecient Garbage collection. Frequent GC pauses and no concurrent deallocation. Comparatively effiecient Garbage collection. Deallocate class data concurrently and not during GC pause.

In previous chapter we saw how we got a permgen space error on running the following program. We analyzed the gc verbose logs. please follow the steps mentioned in that chapter.
package com.javainuse;

public class TestMemory {

	static int i = 0;

	public static void main(String[] args) {

		if (i < 25) {
			main(new String[] { (args[0] + args[0]).intern() });



The gc verbose logs are as below-

See Also

Overriding equals() in Java Internal working of ConcurrentHashMap in Java Image Comparison in Java Java - PermGen space vs MetaSpace Implement Counting Sort using Java + Performance Analysis Java 8 Features Java Miscelleneous Topics Java Basic Topics Java- Main Menu