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...