I have read that using asynctask as an inner class of an activity will cause memory leaks because it won’t let the activity get garbage collected and also due to implicit referencing as well. Will the same memory leaks occur if we used different approaches like:-
- Using AsyncTask in a seperate class ?
- Or if we used AsyncTask with a headless fragment (using its
setRetainInstance(true)
method to avoid its destruction).
I have implemented the headless fragment approach and it works great since the asynctask object is created only once and its controlled by the headless fragment but i can’t figure out if the memory leak of the activity problem is gone or if its still there.