public static void main(String[] args) {
{
String[] f = new String[64*1024*1024];
}
System.gc();
}
运行参数加上 -verbose:gc 查看GC情况
超出作用域因没有其他变量,所以未被重用,收集器不敢回收使用中的变量
public static void main(String[] args) {
{
String[] f = new String[64*1024*1024];
}
int a = 0;
System.gc();
}
f超出作用域,a定义后复用了变量槽,收集器回收内存