gpt4 book ai didi

java - 一个对象有多大,不使用分析器

转载 作者:行者123 更新时间:2023-11-29 05:51:39 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
In Java, what is the best way to determine the size of an object?

我在网上找到了这段代码:

static Runtime runtime = Runtime.getRuntime();
...
long start, end;
Object obj;
runtime.gc();
start = runtime.freememory();
obj = new Object(); // Or whatever you want to look at
end = runtime.freememory();
System.out.println("That took " + (start-end) + "
bytes.");

但它不是很可靠,有什么办法可以做得更好吗?

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