Ai Heng
Ai Heng

Reputation: 21

Why? full gc happen before twice minor gc?

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

Output:

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

Why Full GC before twice Minor GC?

Upvotes: 2

Views: 93

Answers (1)

Eugene
Eugene

Reputation: 121048

The entire point of garbage collection is to do lots of minor collections and very little major collections. How is that happening is of course an implementation detail, but there are numerous posts here on stackoverflow that will shed some light.

What you see is absolutely normal and is just part of a healthy garbage collection process.

Upvotes: 1

Related Questions