Open Draymonders opened 4 years ago
IBM 有专门研究表明,新生代中的对象 98%
都是朝生夕死,所以就不需要按照复制算法中1:1
的比例来划分内存空间。
这里鉴于此,新生代采用了如下的划分策略。
现在把新生代再划分为三部分,一块较大的 Eden
和两块较小的 Survivor
区域。
当执行垃圾回收时,将 Eden
和 Survivor
中还存活着的对象一次性地拷贝到另外一块 Survivor
空间上,最后清理掉 Eden
和刚才用过的 Survivor
的空间。HotSpot 虚拟机默认 Eden 和 Survivor
的大小比例是8∶1,也就是每次新生代中可用内存空间为整个新生代容量的90%
(80%
+10%
),只有10%
的内存是会被 “浪费” 的。
这样清理完成后,原来的 Survivor
就空了,并一直保持为空,直到下次 Minor GC
时,它再作为存活对象的盛放地。两个 Survivor
就这样轮流当做 GC
过程中新生代存活对象的中转站。
todo
2020.08.23 留坑