suja
suja

Reputation: 1278

How is heap size increasing when activity is killed

I don't know if this is asked before but I would like to know how things are working.

I have two activities *Test_Activity* and *Second_Activity*. The Test_Activity have a button to call Second_Activity(called by using and Intent) and in my Second_Activity I have a button to to go back to first one(using Intent). I tried calling second from test then go back to test from second. I tried this for around 10 times (the acitivity is not killed during this time) when i updated i found my heap size increased from 3.027Mb - 4.002Mb.

After that I added *finish()* to the coding when calling the other activity repeated the same process for another 10 times. I found still the heap size increasing. Hows that..?? When the activity is killed isn't it removed from memory...?? If the heap size goes on like this won't my app be killed when it comes to it's maximum limit....?? What's the maximum limit of heap size for an app in android...??

One more thing which I would like to get clarified is how come and app which have only 2 activities(mentioned above) without much resources consume an heap size of 3.027Mb ? I haven't added any drawables or anything.

Upvotes: 3

Views: 482

Answers (1)

gunar
gunar

Reputation: 14710

This growth (3 to 4MB) is absolutely irrelevant. Android may instantiate and keep some resources if it needs. If you're really concerned about memory consumption you should do a memory profiling using MAT. Here's a very technical article about memory management. If you feel that you have some memory leaks in the program (activity hanging somewhere and you don't know where and how) here's a Google IO video presentation that can help you track it.

After that I added *onFinish()* to the coding There is no onFinish callback method called by Android.

The total heap used by an app is not standardized. I have seen the same app on a Sony using 4 to 6 MB and the same app on a Samsung taking between 15 to 20 MB. And it was a very simple app ... It all depends on the manufacturers. As long as you're not leaking big amounts of memory chunks or you're not using resources bigger than you actually need them, you shouldn't worry about these different memory usages.

Upvotes: 4

Related Questions