Junior — Middle
What role does Metaspace play in JVM memory management?
sobes.tech AI
Answer from AI
Metaspace in JVM is responsible for storing class metadata and other information necessary for the operation of the virtual machine. Unlike the former PermGen, Metaspace is allocated in native memory (not in Java heap), allowing for more flexible memory management.
Main functions of Metaspace:
- Storing descriptions of classes, methods, fields, and other class structure information.
- Managing the loading and unloading of classes.
- Preventing OutOfMemoryError errors related to PermGen through dynamic expansion.
Example: When a new class is loaded, the JVM allocates memory in Metaspace for its metadata, and when a class is unloaded, this memory is freed.