【发布时间】:2019-03-11 13:06:44
【问题描述】:
public class Test1 {
public static final int _1MB = 1024 * 1024;
public static void main(String agrs[]) {
gc();
System.out.println("hello world");
}
private static void gc() {
byte[] bytes = new byte[3*_1MB];
byte[] bytes1 = new byte[_1MB];
bytes = null;
byte[] bytes2 = new byte[18*_1MB];
}
}
JDK1.8
-Xms25M -Xmx25M -XX:NewRatio=4 -XX:MaxTenuringThreshold=1 -XX:+UseParallelOldGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps
输出:
0.080: [GC (Allocation Failure) [PSYoungGen: 3677K->496K(4608K)] 3677K->3576K(26112K), 0.0031388 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
0.084: [GC (Allocation Failure) [PSYoungGen: 1520K->0K(4608K)] 4600K->4416K(26112K), 0.0013931 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
0.085: [GC (Allocation Failure) [PSYoungGen: 0K->0K(4608K)] 4416K->4416K(26112K), 0.0009730 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
0.086: [Full GC (Allocation Failure) [PSYoungGen: 0K->0K(4608K)] [ParOldGen: 4416K->1298K(21504K)] 4416K->1298K(26112K), [Metaspace: 2635K->2635K(1056768K)], 0.0027873 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
hello world
为什么在两次 Minor GC 之前进行 Full GC?
【问题讨论】:
-
具体在哪里?
PSYoungGen是之前Full GC -
我认为在 Full GC 之前应该只有一个 Minor GC,但它是两个 Minor GC。字节[] 字节2 = 新字节[18*_1MB];该行代码生成一次Minor GC,然后生成Full GC
-
所以你认为在Full GC之前应该只有一个Minor GC?这种情况你的想法就错了,就这么简单
标签: java java-8 garbage-collection