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.
| 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) {
i++;
System.out.println(i);
main(new String[] { (args[0] + args[0]).intern() });
}
}
}

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
Popular Posts
1Z0-830 Java SE 21 Developer Certification
Azure AI Foundry Hello World
Azure AI Agent Hello World
Foundry vs Hub Projects
Build Agents with SDK
Bing Web Search Agent
Function Calling Agent
Spring Boot + Azure Key Vault Hello World Example
Spring Boot + Elasticsearch + Azure Key Vault Example
Spring Boot Azure AD (Entra ID) OAuth 2.0 Authentication
Deploy Spring Boot App to Azure App Service
Secure Azure App Service using Azure API Management
Deploy Spring Boot JAR to Azure App Service
Deploy Spring Boot + MySQL to Azure App Service
Spring Boot + Azure Managed Identity Example
Secure Spring Boot Azure Web App with Managed Identity + App Registration
Elasticsearch 8 Security - Integrate Azure AD OIDC