为何android 2.x上,DDMS显示使用的内存较小

来源:互联网 发布:软件设计师任职资格 编辑:程序博客网 时间:2024/04/29 22:31

http://stackoverflow.com/questions/13834060/troubleshooting-android-app-memory-usage-problems


重点描述:

Note that if you ran this on Android 1.x/2.x, MAT will not report space consumed by bitmaps. Always try to dump the heap from an Android 3.0+ device or emulator.


Troubleshooting android app memory usage problems

up vote0down votefavorite

I would like to know how I can troubleshoot high memory usage problems of my app on Android. I've search the internet and found out that the DDMS plugin is useful in taking a memory dump of the heap for my app. This however has been useless.

The app "Usage Timelines Free" is showing 94 MBs of memory used, while the DDMS heap dump shows me a total of 8.4 MBs, with the suspected leaks being the resource files.

When I generate a dump from adb (dumpsys meminfo), I get:

                     Shared  Private     Heap     Heap     Heap               Pss    Dirty    Dirty     Size    Alloc     Free            ------   ------   ------   ------   ------   ------   Native       20        8       20    54588    39431     1892   Dalvik     6732     9952     6396    10756    10028      728   Cursor        0        0        0                              Ashmem      184        0      184                           Other dev    11462     1172    11384                            .so mmap     2467     2072     1156                           .jar mmap        0        0        0                           .apk mmap       48        0        0                           .ttf mmap        2        0        0                           .dex mmap     1037        0        0                           

Other mmap 41 16 32

  Unknown    46352      292    46348                               TOTAL    68345    13512    65520    65344    49459     2620

How can I know what is behind this huge memory consumption. My app is a foreground monitor service which runs forever, with a few activities which are accessed a few times per day.

Thanks.

share|improve this question
 
ttlnews.blogspot.in/2010/01/… – Sunny Kumar Aditya Dec 12 '12 at 7:02
 
I already used this... DDMS and got a heap memory dump. It only showed 8.4 MBs being used! – SebouhDec 12 '12 at 7:38

1 Answer

activeoldestvotes
up vote0down voteaccepted

DDMS and got a heap memory dump. It only showed 8.4 MBs being used!

Then you are only using 8.4MB of heap space after a complete garbage collection (a net effect of creating the heap dump).

Note that if you ran this on Android 1.x/2.x, MAT will not report space consumed by bitmaps. Always try to dump the heap from an Android 3.0+ device or emulator.

When I generate a dump from adb (dumpsys meminfo), I get:

My guess is that you are running this on an Android 1.x/2.x device or emulator, and you have a lot of bitmap memory. Try running your heap dump and other tests on an Android 3.0+ environment.

Also, bear in mind that adb dumpsys meminfo does not perform a complete garbage collection, whereas dumping the HPROF file does. The Android garbage collector is optimized to minimize CPU utilization and therefore does not attempt to perform a complete garbage collection. Hence, at runtime, the heap is usually filled with garbage that will be reclaimed, as needed, by the GC engine.

You might also wish to read Dianne Hackborn's essay on this subject.

share|improve this answer
 
Sorry, I should have mentioned that the application is running on my Galaxy Nexus (JB 4.2). These results are generated from there. When you say a lot of bitmap mem, do you mean a lot of bitmap images? I don't. I have a couple of logos and some small icons. Also, what is this "Other dev"? It increases when I open the activity, but doesn't when I exit it. – Sebouh Dec 12 '12 at 13:35
 
@Sebouh: Then your memory usage is perfectly reasonable: 8MB on a Galaxy Nexus is rather small. "When you say a lot of bitmap mem, do you mean a lot of bitmap images?" -- no, I mean a lot of bitmap memory. That could be "a lot of bitmap images" or "a few really huge images". "Also, what is this "Other dev"?" -- some stuff that gets lazy-loaded into your process, apparently, but beyond that I have no idea. – CommonsWare Dec 12 '12 at 13:44
 
Thanks. Then I should not worry about the 94 MBs reported by this timeline app? Also, the "unknown" mem is huge... any idea what that is about? – Sebouh Dec 12 '12 at 13:47
 
@Sebouh: "Then I should not worry about the 94 MBs reported by this timeline app?" -- since you can't control it, and some (perhaps a lot) is actually shared with other processes and not really yours, I would not worry about it. Worry about your heap; the rest is what it is. "Also, the "unknown" mem is huge... any idea what that is about?" -- it is, um, unknown. :-) – CommonsWare Dec 12 '12 at 13:49

原创粉丝点击