开发者

Android - memory leaks, what am I doing wrong?

I have activity A, which launches activity B via an intent. Activity A has no references to Activity B, there are also no references to Activity B in the Application singleton I am using.

When I create Activity B, several thousand objects are created. That's okay, it's 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 the several thousand objects are released. onDestroy() is also called for the activity. I'm using DDMS to view the heap info, and am pressing 'Cause GC' several times to force it to free memory.

I've done the same test on other apps (that use list views too) and 100% of their objects are destroyed on pressing the back button then 'Cause GC', so it's certainly not a bug.

Any advice please? :-) I've read the material in the android docs about leaking contexts, but that's not helpful since i'm not referencing the activity (or anything in it) being destroyed elsewhere. Also, I have many other activities which work the same way, and don't release all memory on destroy. I must be missing something obvious?

Edit: I just realized i'm using AsyncTasks which have references to the activity (either passed as arg into doInBackground() or accessible via outerClass.this. Could they be hanging around in the thread pool, even after onPostExecute() ?

Edit: It leaks even if I go back before running any asynctasks :-(

Edit: No leak before running asynctasks if I remove admob code, but still leaks in 开发者_如何学JAVAthe activites which do use asynctasks.. so asynctask is still a good candidate :-)


I believe there's a bug in the ListView implementation. Take a look at this question: Android: AlertDialog causes a memory leak.

Here's a bug report: http://code.google.com/p/android/issues/detail?id=12334. It's declined but in my opinion it must be reopened.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜