JVM principle | The difference between permanent generation and metaspace

What is a permanent generation?

The permanent generation stores the classes used by the JVM during runtime. The permanent generation also contains the classes and methods of the Java SE library. The permanent generation is not part of the Java heap memory. Permanent generation objects are garbage collected during Full GC.

What is MetaSpace?

After JDK1.8, the permanent generation is replaced by metaspace, which is used to store large objects;

The biggest difference between the two:

Insert picture description here

  1. Metaspace uses local memory
  2. The permanent substitute is jvm memory

Metaspace advantages:

Resolved the "java.lang.OutOfMemoryError: PermGen space "occurrence of anomalies

  1. To solve the 空间不足problem (the old era of string or memory occupied by objects could not be determined, depending on the local memory element space memory), because the metadata assigned default class is limited only by the size of the local memory, that is to say, the local memory In theory, the amount of remaining metaspace can be as large as possible, which solves the problem of insufficient space, but it is impossible to let it grow infinitely. By default, the JVM will dynamically set its size according to the needs at runtime;

Why 空间不足?

The JVM has limited memory, and the permanent generation generally stores large objects such as string constant pools, objects, etc., so it is easier to fill up

Guess you like

Origin blog.csdn.net/weixin_40597409/article/details/115260077