0

I have a Live Wallpaper app that uses photos downloaded from web to use as a wallpaper.

Memory managers show that my app is using between 90MB and 120MB (it's a device with 1GB RAM). That is a lot. Wallpaper service get's killed often, and sometimes system even reverts to default static wallpaper.

Although I checked thoroughly for any memory leaks and HPROF dump analysis shows that I only have 2 large objects in use: currently used Bitmap for wallpaper (16MB - and this is expected for a 4Mpix image) and class android.content.res.Resource (12MB) with total of 32MB as reported in HPROF overview screen.

dumpsys meminfo shows this:

** MEMINFO in pid 1354 [com.myapp.lwp] **
                     Shared  Private     Heap     Heap     Heap
               Pss    Dirty    Dirty     Size    Alloc     Free
            ------   ------   ------   ------   ------   ------
   Native       16       16       16   112304     5274      993
   Dalvik    41947    19316    41428    74572    53120    21452
   Cursor        0        0        0
   Ashmem        0        0        0
Other dev    20170    33176     3460
 .so mmap     5690     2620     1504
 .jar mmap        0        0        0
 .apk mmap       64        0        0
 .ttf mmap        6        0        0
 .dex mmap      604        0        4
Other mmap     1035      300      272
  Unknown     5127      472     5116
    TOTAL    74659    55900    51800   186876    58394    22445

Objects
           Views:       27         ViewRootImpl:        0
     AppContexts:        4           Activities:        1
          Assets:        3        AssetManagers:        3
   Local Binders:       16        Proxy Binders:       23
Death Recipients:        0
 OpenSSL Sockets:        1

I read this: How do I discover memory usage of my application in Android? but it doesn't help me to conclude anything...

I also used:

    cat /proc/1354/statm
    139422 29326 11550 2 0 10330 0

It doesn't help much either.

DDMS shows 63MB heap size.

My questions are? Is it normal and expected of an app that deals with images of double the screen size? If not, what is in remaining 60-90MB? (i subctract 30MB that HPROF gave me for total). What possible can I be doing wrong in my app to use so much memory? What app actualy do:

1) Download list of photos (max 100) as JSON string and parse that string to get ids and urls for these photos.
2) Download first photo and save it to cache folder
3) Decode photo and if necessary resize it to fit 2Width*Height of screen (photos are actualy smaller that my Full HD screen).
4) Draw it on wallpaper canvas (and draw repeatedly while user is scrolling)
5) If on WIFI download next 10 photos to cache folder (without decoding, just saving)

I have other modes more complicated with more photos simultaneously used but above memory usage is for most simple scenario.

It's not a problem of continuous usage - memory is as described after first start: If I kill the service, after restart it uses 90MB. After first opening of options screen (small activity/dialog with several options to choose - no graphics except background drawables) memory usage jumps to 124MB and returns to 112MB after screen is closed. After first change of wallpaper photo it jumps to 130+ and returns to 120+. Probably because heap size is increased during bitmap decoding and then stays that way.

What should I do? How to decrease (if it is possible at all) my app memory footprint? Where else to look? I don't expect ready solution but any further guidance can help...

Community
  • 1
  • 1
CloudWalker
  • 313
  • 4
  • 12

1 Answers1

1

I had the same problem while working on my application. The DUMP and the GC (From Logcat) were both indicating that I'm using around 30-50 MB of memory, fluctuating up and down, which is normal since the GC is running at different times.

However, for some reason it seems the process RAM usage was just building up and not getting released, especially if you have a running service. My process showed that I hit over 300 MB of RAM, so I wasn't sure whether it's just not released (GCed already) or it's being leaked.

What I did to verify is, I let it be for a while after closing the application, and in few hours it showed my service is using 3 MB of RAM only, also, I opened many applications (To force the Android to perform a GC) and again it went back from 300 MB to 3 MB without killing my service, so I assume it just kept building it up without GCing it, so it wasn't leaked.

This is still not a good enough insurance but it's better than nothing, I'm working on trying to find out more about it, hope that helps.

Kindly let me know if you ever figure out the solution to that problem, thanks.

NightwareSystems
  • 433
  • 5
  • 17