/**
* 测试垃圾回收机制
* @author zk_zyzs@aliyun.com
*
*/
public class Test {
private Object instance;
public static void main(String[] args) {
//创建引用
Test test =new Test();
Test test2=new Test();
//设置引用
test.instance=test2;
test2.instance = test;
//释放对象
test=null;
test2=null;
System.gc();
}
}
[GC (System.gc()) [PSYoungGen: 1996K->632K(38400K)] 1996K->640K(125952K), 0.0019813 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (System.gc()) [PSYoungGen: 632K->0K(38400K)] [ParOldGen: 8K->521K(87552K)] 640K->521K(125952K), [Metaspace: 2642K->2642K(1056768K)], 0.0096864 secs] [Times: user=0.05 sys=0.00, real=0.01 secs]
Heap
PSYoungGen total 38400K, used 333K [0x00000000d5d00000, 0x00000000d8780000, 0x0000000100000000)
eden space 33280K, 1% used [0x00000000d5d00000,0x00000000d5d534a8,0x00000000d7d80000)
from space 5120K, 0% used [0x00000000d7d80000,0x00000000d7d80000,0x00000000d8280000)
to space 5120K, 0% used [0x00000000d8280000,0x00000000d8280000,0x00000000d8780000)
ParOldGen total 87552K, used 521K [0x0000000081600000, 0x0000000086b80000, 0x00000000d5d00000)
object space 87552K, 0% used [0x0000000081600000,0x00000000816827b8,0x0000000086b80000)
Metaspace used 2648K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 285K, capacity 386K, committed 512K, reserved 1048576K
************执行虚拟机需要配置如下参数:-verbose:gc -XX:+PrintGCDetails ***************
从执行结果可以看出垃圾回收机制用的叫 Parallel