查看java中对象占用内存的大小
导入依赖
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>4.0.0</version>
</dependency>
demo
public static void main(String[] args) {
byte[] bytes = new byte[1024];
String objectSize = RamUsageEstimator.humanSizeOf(bytes);
System.out.println("objectSize内存大小为: "+objectSize);
}
输出结果
objectSize内存大小为: 1 KB