java 查看对象内存占用大小

2022-01-02 00:00:00 对象 大小 占用

1、POM 依赖

<dependency>
	<groupId>com.carrotsearch</groupId>
	<artifactId>java-sizeof</artifactId>
	<version>0.0.5</version>
</dependency>

/2、java 代码通过RamUsageEstimator 查看内存占用大小

        String str = "xxx";
        T object = JSONObject.parseObject(str, T.class);
        byte[] bytes = ProtostuffRuntimeUtil.serialize(object);
        long l = RamUsageEstimator.sizeOf(object);
        long bytesL = RamUsageEstimator.sizeOf(bytes);
        System.out.println("object:" + l + ",bytes:" + bytesL);

    原文作者:CottonDuke
    原文地址: https://blog.csdn.net/CottonDuke/article/details/124455894
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。

相关文章