安卓:Eclipse的MAT似乎并没有表现出我所有的应用程序的对象有的、并没有、表现出、我所

由网友(人事已非)分享简介:我已经通过插入语句 Debug.dumpHprofData创建的HPROF文件(/ SD卡/ myapp.hprof); 在我的应用程序的code;我有那么贯穿HPROF-CONV的HPROF文件,并​​在Eclipse中打开转换后的文件。继MAT的意见小抄我已经得到我的应用程序的内存使用情况的分析,通过将泄漏辨识 -...

我已经通过插入语句 Debug.dumpHprofData创建的HPROF文件(/ SD卡/ myapp.hprof); 在我的应用程序的code;我有那么贯穿HPROF-CONV的HPROF文件,并​​在Eclipse中打开转换后的文件。

继MAT的意见小抄我已经得到我的应用程序的内存使用情况的分析,通过将泄漏辨识 - >组件报告。com prepbgg *进入和击球完成

我知道,我的应用程序占用大量的内存:特别是在那里我叫dumpHprofData的阶段,它有一个万像素的位图对象和画布必须消耗几百KB。 (我还怀疑是漏水显著大量的内存,因为性能下降严重后屏幕已被旋转了几下。)

不过,组件报告融为一体。prepbgg。*表示只有38.7KB的内存总量。直方图视图显示android.graphics.Bitmap(presumably这是所有应用程序,包括矿山的总和)404对象和浅堆12928。那是12928个字节?

显然,我的应用程序消耗超过38.7KB和位图远远超过12928字节。我在哪里的问题呢?我怎么能看到我的应用程序消耗的总内存?

解决方案

大多数为位图的空间将是本机堆。看到源为位图:它拥有七大领域。假定每个字段为四个字节(参考值和整数几乎可以肯定,并合理的布尔值)为对象头添加一个额外的4字节,:

 (7 * 4 + 4)* 404 = 12928
 

我不认为有任何简单的方法来检查本机堆而不运行自己的身材呢。

您可以问多少东西是被分配:的http://developer.android.com/reference/android/os/Debug.html#getNativeHeapAllocatedSize()

eclipse mat使用教程

I have created an hprof file by inserting the statement Debug.dumpHprofData("/sdcard/myapp.hprof"); in my app's code; I have then run the hprof file through hprof-conv and opened the converted file in Eclipse.

Following the advice of the MAT "Cheat Sheet" I have obtained an analysis of my app's memory usage by going to "Leak Identification -> Component Report" entering "com.prepbgg.*" and hitting Finish.

I know that my app is consuming large amounts of memory: in particular at the stage where I called dumpHprofData it had a one megapixel bitmap object and a canvas that must have consumes several hundred KB. (I also suspect that it is leaking significant amounts of memory because performance degrades severely after the screen has been rotated a few times.)

However, the Component Report for com.prepbgg.* shows total memory of only 38.7KB. The Histogram view shows for android.graphics.Bitmap (presumably this is the total of all apps including mine) 404 objects and Shallow Heap 12,928. Is that 12,928 bytes?

Clearly, my app consumes more than 38.7KB and the Bitmap far more than 12,928 bytes. Where am I going wrong? How can I see the total memory consumed by my app?

解决方案

most of the space for the bitmap will be on the native heap. see the source for Bitmap: it has seven fields. assume each field is four bytes (almost certain for the reference and ints, and plausible for the booleans) add an extra four bytes for the object header, and:

(7*4 + 4) * 404 = 12928

i don't think there's any easy way to examine the native heap without running your own build yet.

you can ask how much stuff's been allocated: http://developer.android.com/reference/android/os/Debug.html#getNativeHeapAllocatedSize()

阅读全文

相关推荐

最新文章