PermGen (Permanent Generation)
1. It is a special heap space separated from the main memory heap
2. It has a fixed size, it can’t be expanded at runtime and is not eligible for garbage collection
3. The JVM keeps track of loaded class metadata in the PermGen
4. JVM stores all the static content in this memory section that includes all static methods, primitive variables and references to the static objects
5. it contains data about byte code, names and JIT information
6. with its limited memory size, PermGen is involved in generating the famous OutofMemoryError because the class loaders weren’t garbage collected properly and as a result, generated memory leak
7. Before java 7, string pool was also part of this memory but later string pool is stored in the Heap space which is garbage collected by JVM. The advantage of this approach is the reduced risk of OutOfMemory error because unreferenced Strings will be removed from the pool, thereby releasing memory.
Metaspace
1. starting from the Java 8 version; it has replaced the older PermGen memory space. The most significant difference is how it handles memory allocation
2. specifically, this native memory region grows automatically by default
3. Additionally, the garbage collection process also gains some benefits from this change. The garbage collector now automatically triggers the cleaning of the dead classes once the class metadata usage reaches its maximum metaspace size
4. Therefore, with this improvement, JVM reduces the chance to get the OutOfMemory error