Solving memory leak

Search This thread

Maceee

Senior Member
Jul 2, 2012
712
104
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
 
Last edited:

SimplicityApks

Senior Member
May 26, 2013
354
344
Aachen
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

Senior Member
Jul 2, 2012
712
104
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