views:

87

answers:

3

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
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
Not necessarily. It returns an approximate value of the size, that too dependent on the implementation.
Ravi Gupta
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