0

I was working on my app, when I noticed that the memory usage of my app just keeps climbing....steadly...forever...and every once in a while, the Garbace Collector kicks in, and cuts down the memory usage.

Eventually, I found out that this is the case even for the template Hello World application as well.

Why is this happening? Is it happening for you? How can I make the memory usage stop increasing for no reason? I don't remember this being an issue before...I'm going nuts yo!

Here is a picture of the Hello World app, and its memory usage.

Hello World app, and memory usage

1 Answer 1

6

An Android app in its entirety doesn't consist of just client (your) code. In addition an app will also have a GUI aspect, which implies that it is being run in a loop and that it needs to be re-drawn every time. It is easy to speculate that there is at least one object allocation that happens inside that loop (there may as well be more than just one). Considering the fact that the reference to the aforementioned object gets out of scope, GC will only mark it and doesn't immediately free memory. Hence, the new objects will constantly consume more available memory. When there's no free memory to allocate, the GC will take care of the marked objects and there is now free memory to grab again. This is roughly what you can see on the picture above. This is a normal behavior and not something you should be worried about. Generally speaking, most optimizations and profiling should be done after the main application logic is complete.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.