Sunday, 11 August 2013

High memory usage on application start in Android

High memory usage on application start in Android

I'm making a basic android application, but it is suffering from a LOT of
garbage collection (the GC kicks in 4-5 times every second). I tried
looking for the root cause and realized that my app has almost no memory
as soon as the onCreate function is called.
As soon as the app starts, the DDMS shows almost 91% of the heap being
used, mostly by 1-byte arrays. I also ran the memory analysis tool to see
if I was leaking memory or something, and even after executing the app, it
shows that most of the memory is used up by android.content.res.resources.
Why is my application losing so much memory to resources? The ONLY
resource that my app has is a small JPEG image of 22KB. I read elsewhere
that sometimes the free heap is misreported because of shared resources
etc, but then the GC shouldn't kick in as often as it does when the app is
running. Can someone help?
FWIW, the very same app run on a Galaxy S3 shows about 20% heap usage at
the start, even though it shows the same amount of total memory (~10 MB).
The problematic phone is a Galaxy S2.

No comments:

Post a Comment