代码:
-verbose:gc -Xms20M -Xmx30M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 -Xloggc:F:\gc1.log
1.首先配置
Run -> Run configuration
实例代码:
package example2;
public class Main {
private Object instance;
public Main () {
byte[] m = new byte[20*1024*1024];
}
public static void main(String[] args) {
Main m1 = new Main();
Main m2 = new Main();
m1.instance = m2;
m2.instance = m1;
m1 = null;
m2 = null;
System.gc();
}
}
这里定义2个对象的引用,m1的引用是m2,m2的引用是m1.并且都与外界断了联系,故意扩大内存地址。