MinorGC 与 Full GC 区别
新生代GC(Minor GC):是指在新生代的垃圾收集动作,因为java对象大多都具备朝生夕死的特性,所以Minor GC 非常频繁,一般回收速度也比较快。
代码实例:
package com.Studay.GC;
public class MinorGC {
public static final int _1MB = 1024*1024;
/**
* VM 参数: -verbose:gc -Xms20m -Xmx20m -Xmn10m -XX:+PrintGCDetails
* -XX:SurvivorRatio=8
*
* 参数意义:将堆最大与最小设置为20m,其中年轻代分为10m
*
*/
public static void main(String[] args) {
byte[] allocation1,allocation2,allocation3,allocation4;
allocation1 = new byte[_1MB * 2];
allocation2 = new byte[_1MB * 2];
allocation3 = new byte[_1MB * 2];
allocation4 = new byte[_1MB * 4]; //出现一次Minor GC
}
}
代码讲解:
执行分配allocation的时发生了一次Minor GC ;
[GC (Allocation Failure) [DefNew: 7127K->518K(9216K), 0.0030483 secs] 7127K->6662K(19456K), 0.0030837 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
Heap
def new generation total 9216K, used 4696K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
eden space 8192K, 51% used [0x00000000fec00000, 0x00000000ff014930, 0x00000000ff400000)
from space 1024K, 50% used [0x00000000ff500000, 0x00000000ff581828, 0x00000000ff600000)
to space 1024K, 0% used [0x00000000ff400000, 0x00000000ff400000, 0x00000000ff500000)
tenured generation total 10240K, used 6144K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
the space 10240K, 60% used [0x00000000ff600000, 0x00000000ffc00030, 0x00000000ffc00200, 0x0000000100000000)
Metaspace used 2634K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 281K, capacity 386K, committed 512K, reserved 1048576K
老年代GC(Major GC / FullGC):是指发生在老年代的GC,
上一篇: JVM Full GC分析
下一篇: 面试那些事————网络编程之socket
推荐阅读
-
System.gc()与Runtime.getRuntime().gc()区别
-
System.gc()与Runtime.getRuntime().gc()区别
-
jstat显示的full GC次数与CMS周期的关系
-
CMS再优化与频繁Full GC问题分析
-
finalize与gc的区别
-
Minor GC和Full GC有什么区别?
-
Java虚拟机6:内存溢出和内存泄露、并行和并发、Minor GC和Full GC、Client模式和Server模式的区别
-
Minor GC、Major GC和Full GC之间的区别
-
Minor GC、Major GC、Full GC以及Mixed GC之间的区别
-
JVM自动内存管理,Minor GC与Full GC的触发机制