androiddev androiddev - 4 months ago 9x
Android Question

How async tasks and cursors lead to memory leak?

Would like to have a deeper understanding of the same on how async task on orientation changes can lead to memory leak. I have done my bit of research but couldn't find a precise solution


Normally when the orientation changes, Android framework destroys the activity (garbage collects the memory allocated) and creates a new one.

Now say you are running an AsyncTask which holds a reference to an Activity class object and the orientation changes. Here, Android framework would not be able to destroy the activity (as it is still referenced by your AsyncTask) while a new one will be created in its place. This is one of the ways how memory leaks happen.