JVM探秘 | 垃圾回收机制

2017-03-27

垃圾收集是什么

Automatic garbage collection is the process of looking at heap memory, identifying which objects are in use and which are not, and deleting the unused objects. An in use object, or a referenced object, means that some part of your program still maintains a pointer to that object. An unused object, or unreferenced object, is no longer referenced by any part of your program. So the memory used by an unreferenced object can be reclaimed.

按代回收机制

gc-generation

Young Generation

Old/Tenured Generation

Metaspace

In JDK 8, classes metadata is now stored in the native heap and this space is called Metaspace.

垃圾收集算法

标记-清除算法(Mark-Sweep)

复制算法(Copying)

标记-压缩算法(Mark-Compact)

分代收集算法(Generational Collection)

垃圾收集器

Serial GC

-XX:+UseSerialGC

ParNew GC

-XX:+UseParNewGC

Parallel GC

-XX:+UseParallelGC

Parallel Old GC

-XX:+UseParallelOldGC

CMS GC

-XX:+UseConcMarkSweepGC

G1 GC

参考资料