What is the use of MetaSpace in Java 8?

后端 未结 3 1421
面向向阳花
面向向阳花 2020-12-02 06:12

I know they have replaced PermGen with MetaSpace in Java 8. But I have few questions:

  1. Is MetaSpace by default is GC collected?
  2. Even the PermGen is GC
3条回答
  •  臣服心动
    2020-12-02 06:29

    In response:

    1. By default the Metaspace memory is collected if it reaches the MaxMetaspaceSize. This parameter is initially unlimited. The limit is the memory in your machine. But the memory is automatically freeded when a class and class loader is no longer needed. You only need to tune this parameter if you suspect that the ClassLoader has a memory leak.

    2. The MetaSpece use native memory and the organization in memory with pointers makes that the GC are faster than older PermGen memory.

    3. No, it means that the JVM use the memory like common C program and don't use the virtual memory space for java objects. That seems that the memory is only limited by the machine. Take care that the memory of the machine can be swapped to disk if needed.

    4. If you set the parameter MaxMetaspaceSize you can get OutOfMemory and, if you don't set this parameter you can get if the process allocate all the machine memory (including swap space).

提交回复
热议问题