gpt4 book ai didi

java - System.gc() 收集仍然被局部变量引用的对象

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:01:11 25 4
gpt4 key购买 nike

<分区>

当我运行下面的程序时

public static void main(String[] args) {

ArrayList<Object> lists = new ArrayList<>();
for (int i = 0; i <200000 ; i++) {
lists.add(new Object());
}
System.gc();
try {
Thread.sleep(Integer.MAX_VALUE);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

然后我转储堆

jmap -dump:live,format=b,file=heap.bin 27648
jhat -J-Xmx2G heap.bin

ArrayList 和 200000 个对象丢失了。

不知道为什么JVM知道对象不会被使用以及为什么JVM判断这个GC根不是引用。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com