MinorGC 与 Full GC 区别

版权声明:如果是原创,请联系作者进行转载 https://blog.csdn.net/u013159507/article/details/83012762

新生代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,

猜你喜欢

转载自blog.csdn.net/u013159507/article/details/83012762
今日推荐