简体   繁体   English

使用工具获取对象大小

[英]Fetching Object Size using Instrumentation

I have an object which is a composite of several other objects. 我有一个对象,它是其他几个对象的组合。 When i use the getObjectSize() method in the Instrumentation package, does it include the size of the composite objects also? 当我在Instrumentation包中使用getObjectSize()方法时,它也包括复合对象的大小吗?

The API doc says: API 文档说:

The result may include some or all of the object's overhead, and thus is useful for comparison within an implementation but not between implementations. 结果可能包括对象的部分或全部开销,因此对于实现内部的比较有用,但对于实现之间的比较有用。 The estimate may change during a single invocation of the JVM. 在JVM的一次调用期间,估计值可能会更改。

No. The returned size reflects the size of that object - it includes the references that object holds, but not the size of the objects being referred to. 否。返回的大小反映该对象的大小-它包括该对象保存的引用,但不包括所引用对象的大小。 (And, as others have noted, it's not guaranteed to actually be correct.) (而且,正如其他人指出的那样,不能保证它实际上是正确的。)

getObjectSize(Object obj)返回指定对象( obj )消耗的存储空间...因此,您将获得要指定的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM