Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,772,940 Members 46,912 Now Online
XDA Developers Android and Mobile Development Forum

Solving memory leak

Tip us?
 
Maceee
Old
(Last edited by Maceee; 20th June 2014 at 11:55 AM.)
#1  
Senior Member - OP
Thanks Meter 105
Posts: 702
Join Date: Jul 2012
Default Solving memory leak

I am a beginner developer and I am sure I have a memory leak in my android application. When I open my app for the first time and check the heap size using DDMS tool from Eclipse it shows 4.5 MB. With every new opening of my app (close and reopen it) the heap size is increasing until it reaches 5.8 MB and then it settles at this size going up or down just a little bit. I also see that the amount of allocated objects increases from 44k to 60k. That is crazy I guess. But why it stops increasing at that particular point of memory (5.8 MB) and amount of objects (60k)? Furthermore, for some reason Android Application Manager's "Cached background processes" section shows that my app memory consuption increases from 10 MB to 24 MB and settles there. Why do these numbers differs from what DDMS shows? Anyway, these two tools show the same behaviour: that is with every opening my app's memory is increasing. I have tried setting all my instance variables to null in onDestroy() methods of my every activity or fragment but it didn't help. What else can I do?

Sent from my GT-I9300 using XDA Free mobile app
 
SimplicityApks
Old
#2  
SimplicityApks's Avatar
Senior Member
Thanks Meter 324
Posts: 311
Join Date: May 2013
Location: Aachen
Quote:
Originally Posted by Maceee View Post
I am a beginner developer and I am sure I have a memory leak in my android application. When I open my app for the first time and check the heap size using DDMS tool from Eclipse it shows 4.5 MB. With every new opening of my app (close and reopen it) the heap size is increasing until it reaches 5.8 MB and then it settles at this size going up or down just a little bit. I also see that the amount of allocated objects increases from 44k to 60k. That is crazy I guess. But why it stops increasing at that particular point of memory (5.8 MB) and amount of objects (60k)? Furthermore, for some reason Android Application Manager's "Cached background processes" section shows that my app memory consuption increases from 10 MB to 24 MB and settles there. Why do these numbers differs from what DDMS shows? Anyway, these two tools show the same behaviour: that is with every opening my app's memory is increasing. I have tried setting all my instance variables to null in onDestroy() methods of my every activity or fragment but it didn't help. What else can I do?
Are you really sure you have such a leak? Usually it happens on rotation or so and it keeps on increasing, using far more memory than your 5.8 megs. If you quit your app with the home button (instead of back) Android still keeps a lot of its data in memory so it is faster to be reopened. It still depends on what your app is doing, so releasing any unneeded receivers or caches is still a good thing to do, but in your case an increase of just 1.3MB is not significant enough to really worry about it. I don't know what the Android Application Manager is showing since I haven't used it yet.
 
Maceee
Old
#3  
Senior Member - OP
Thanks Meter 105
Posts: 702
Join Date: Jul 2012
Quote:
Originally Posted by SimplicityApks View Post
Are you really sure you have such a leak? Usually it happens on rotation or so and it keeps on increasing, using far more memory than your 5.8 megs. If you quit your app with the home button (instead of back) Android still keeps a lot of its data in memory so it is faster to be reopened. It still depends on what your app is doing, so releasing any unneeded receivers or caches is still a good thing to do, but in your case an increase of just 1.3MB is not significant enough to really worry about it. I don't know what the Android Application Manager is showing since I haven't used it yet.
Well, I wouldn't worry if that 5.8 MB had gone down after I quit my app pressing back button, but it hadn't, so it keeps me thinking I have a memory leak. And yes, it keeps on increasing on rotation too, because the activity is recreated. It doesn't increase only when I close and open my app using home button because activity isn't recreated then. By the way, I use FragmentPagerAdapter for ViewPager and CursorAdapter for ListView. Maybe one of these could be the cause. Thank you.

Sent from my GT-I9300 using XDA Free mobile app
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes