Android & Dalvik - Get the size of an object

前端 未结 3 1865
一整个雨季
一整个雨季 2020-12-28 16:12

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

3条回答
  •  灰色年华
    2020-12-28 16:51

    For this problem, it is better not to use a programatic approach but to use the Memory Analyzer Tool (MAT) from www.eclipse.org/mat/ It has both standalone version and plugin for Eclipse. With it you can create a snapshot of Dalvik heap and then you could sort the list of objects by their size or also by the size of their referenced objects (retained size). I used this exactly for troubleshooting a bitmap cache leaks.

提交回复
热议问题