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?
A:
The API doc says:
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.
Ravi Gupta
2010-03-12 06:05:50
A:
getObjectSize(Object obj)
returns the storage consumed by the specified object (obj
)... so you will get the size of whatever you will specify.
Webbisshh
2010-03-12 06:08:04
Not necessarily. It returns an approximate value of the size, that too dependent on the implementation.
Ravi Gupta
2010-03-12 07:14:57
A:
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.)
Sbodd
2010-03-12 16:03:53