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);