I have an application that uses a Service and some list activities. When the activities are opened, I can see the heap usage increase in DDMS, when the activities are closed
I had the very same problem but I found out that the problem only occurred when I was debugging. On a "normal" run all the activities are gone.
If it repeatedly (10-15 times) open the activity then close the activity, the heap size (both MB and # Objects) balloons!
Have you run the garbage collector? There's a button for that in DDMS.
Once you have run the garbage collector and it seems to be coming up with nothing to collect (as logged in LogCat), you can always dump the heap and inspect it with MAT or jhat.
Am I using ListActivity incorrectly?
Delete all occurrences of getApplicationContext()
in your activity and replace them with this
. The activity is a Context
, and you want to be using the Activity
in those places.
Similarly, I don't know why you are calling getBaseContext()
in the Service
, rather than just using this
, since Service
too is a Context
.