SETUP :
I have this app which has 4 activities in a linear path, really simple navigation :
A -> B -> C -> D
All the activities share the same background image and all have a couple of regular buttons, a textview or an edittext. All of which are defined in separate views xml files.
The background is a gradient and is kind of heavy. Around 3 megs as an uncompressed bitmap.
The app does nothing yet, the only logic in it, is for starting activities and closing them on button clicks
I tried to use MAT to find a memory leak but couldn't find anything. The biggest retained size in my app is 656(ko?) the total retained size for the app is 1520(ko?) and I can't find any object that would be duplicated.
Which by the way completely contradicts dumpsys which shows 27300(ko?) allocated
PROBLEMS :
- When I navigate UP, I see an increase of memory usage equivalent to the background size.
- When I navigate DOWN, closing the activities with the back button or a finish command, the memory usage of the app does not decrease.
- If I go from A to D then back to B and rotate the screen, the app force closes with an OutOfMemory Exception.
QUESTIONS :
Update : I guess the real question is why do I have a huge memory leak(5 megs at a time) with a 27megs app size at freeze time and I can not see it in the MAT ?
- Why would Android decompress multiple times the same background, once per activity ? Seems inefficient.
- Is it possible to overcome this problem by using themes or will I see the same "allocate 1 background by activity" weirdness ?
- Why are the activities not reclaimed when closed ?
- Why are MAT and dumpsys presenting different numbers ?
CLUES
At exactly the same time I have :
dumpsys meminfo :
Applications Memory Usage (kB):
Uptime: 74006853 Realtime: 110962243
** MEMINFO in pid 22683 [com.kayenko.sosadresse] **
native dalvik other total
size: 20820 5767 N/A 26587
allocated: 18751 2901 N/A 21652
free: 312 2866 N/A 3178
(Pss): 1357 201 16782 18340
(shared dirty): 2264 1804 5456 9524
(priv dirty): 1280 116 16032 17428
Objects
Views: 0 ViewRoots: 0
AppContexts: 0 Activities: 0
Assets: 2 AssetManagers: 2
Local Binders: 18 Proxy Binders: 16
Death Recipients: 1
OpenSSL Sockets: 0
SQL
heap: 0 MEMORY_USED: 0
PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 0
And this dominator tree :
Thansk to anyone with a clue on what I'm suppose to look for.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…