I have a memory leak using ListActivity in Android

后端 未结 2 1778
面向向阳花
面向向阳花 2020-12-11 06:36

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

相关标签:
2条回答
  • 2020-12-11 07:26

    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.

    0 讨论(0)
  • 2020-12-11 07:30

    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.

    0 讨论(0)
提交回复
热议问题