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.
Apple and Google both have fantastic app stores. But Android is far superior at organizing apps, letting you put important stuff on the home screens and hide less useful apps in the app drawer. Also, Android's widgets are much more useful than Apple's.
Android OS is a Linux-based mobile operating system that primarily runs on smartphones and tablets. The Android platform includes an operating system based upon the Linux kernel, a GUI, a web browser and end-user applications that can be downloaded.
Android Inc., was bought by the American search engine company Google Inc., in 2005. At Google, the Android team decided to base their project on Linux, an open source operating system for personal computers.
The latest version of Android OS is 12, released in October 2021. Learn more about OS 12, including its key features. Older versions of Android include: Tiramisu (OS 13)
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 in dvmAllocObject()
in dalvik/vm/alloc/Alloc.cpp and the dvmTrackAllocation()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With