Reputation: 3730
I have a strange memory behavior in an Android application I'm developing. The application is running fine, but if I look to a "task manager" in Android, like the Samsung SII task manager or the "Memory Usage" application on a Nexus 7 it shows that while using the app the amount of memory used is rapidly growing to an insane amount, like hundreds of megas (600~700MB on the Nexus 7). Then it can fall down back to about 200MB, grow again etc.
At first I thought that I had a bad memory leak and started to search for the problem in the Eclipse Memory Analyzer (MAT) like it is explained in this excellent video. But the problem is that from here everything looks ok. I didn't find any duplicate instance of an activity or anything else that could cause the leak, and the reported amount of memory used is a lot smaller. The problem also doesn't appear in the GC messages. So I can have a 600MB use reported in the Task manager, and something like this in Logcat:
01-29 12:05:44.511: D/dalvikvm(6044): GC_FOR_ALLOC freed 3930K, 24% free 28959K/38096K, paused 17ms, total 17ms
with a heap amount never going above 50~60MB (which could be normal because there are lots of pictures in the app). Numbers in MAT match.
I would like to bu sure that there is a memory leak or not in my application. Even if GC messages and MAT don't report problems, I find it really strange that the task managers report such a high memory usage. Maybe someone here already faced such a strange behavior and could give me a clue about what is happening?
Upvotes: 1
Views: 352
Reputation: 3730
Ok, after hours of testing I've finally found the problem. As guessed by fadden, the leak was out of the Dalvik's scope. It was in fact due to the following bug in Typeface.createFromAsset:
http://code.google.com/p/android/issues/detail?id=9904
This method is leaking asset stream. My app is using a custom TextView to display text with custom fonts, and as it is used in most of the layout files it was rapidly leaking a lot of RAM, but not in Dalvik's heap, so it was really difficult to spot using the usual tools.
Upvotes: 1
Reputation: 52303
The GC messages only show what's on the Dalvik heap. The native heap can grow without bound -- until the system decides to kill you, which it is reluctant to do so long as you're in the foreground. Does your app have a native component that could be causing the allocations?
If this is a developer / rooted device, the "procrank" tool can give you a quick summary of memory usage. The "showmap " tool can give you a more detailed breakdown.
DDMS has some (officially unsupported) tools for examining native memory usage. Google for "ddms native heap" to find some instructions.
Upvotes: 1