As we all know Java 5 introduced the ability for Instrumentation to get the size of an object with ease. Is there such a method on Android and Dalvik?
The java.lang.instrument package is not available on Android.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For what it’s worth, I have looked at the Dalvik VM source code and can not find any stable API to get the size of an Object. If you want to take a look yourself, the size of an object is stored in
ClassObject::objectSize : size_t, see dalvik/vm/oo/Object.h.There is, however, internal APIs to get the size of an Object. It is used by DDMS to report detailed information about object sizes. But, since the API is internal, it is likely to change between different versions of Android. Plus, the API is sends raw
byte[]data around, and is client/server based and not a simple library call, so it will be extremely awkward to use. If you want to take a look, start indvmAllocObject()in dalvik/vm/alloc/Alloc.cpp and thedvmTrackAllocation()call.To sum it up: there is unfortunately not any readily usable, stable API to get the size of an Object in the Dalvik VM.