Android - memory leak, what am I doing wrong?

I have activity A that triggers action B through intent. Activity A has no links to Activity B, and there are no links to Activity B in the singleton application that I use.

When I create Activity B, several thousand objects are created. This is good, this is an activity with a very populated ListView with lots of images.

But when I press the "Back" button and return to "Activity A", only about a dozen of several thousand objects are displayed. onDestroy () is also called for activity. I use DDMS to view heap information, and I click "Cause GC" several times to make it free up memory.

I did the same test in other applications (which also use lists), and 100% of their objects are destroyed when you click the "Back" button and then "Reason GC", so this, of course, is not an error.

Any advice, please? :-) I read the material in the android docs about context leaks, but this is not useful, since I do not refer to the activity (or something in it) that was destroyed elsewhere. In addition, I have many other actions that work the same and do not free up all memory when destroyed. Should I miss something obvious?

Editing: I just realized that I am using AsyncTasks that have activity links (either passed as arg to doInBackground () or accessible via externalClass.this. Can they hang in the thread pool even after onPostExecute ()

Edit: it flows even if I go back before starting any asintets :-(

Edit: leaks do not run asynctasks if I delete the admob code, but still flowing in assets that use asynctasks .. so asynctask is still a good candidate :-)

+4
source share
1 answer

I believe that there is an error in the implementation of ListView . Take a look at this question: Android: AlertDialog causes a memory leak .

Here is the error report: http://code.google.com/p/android/issues/detail?id=12334 . He deviated, but, in my opinion, he should be reopened.

+2
source

All Articles