I am loading few images in a ListView using AsyncTask. It looks something like that:
private void loadImageInBackground(ViewHolder holder, Location location) {
ImageViewLoader coverImageLoader = new ImageViewLoader(holder.locationImage, coversImgCache);
coverImageLoader.execute(location.getImageUrl());
}
Where ImageViewLoader is just an extended AsyncTask.
From what I understand, garbage collector collects everything that is not referenced anymore.
As the stack pointer leaves the function above, the class loses any references on the created ImageViewLoader object. This should be then garbage collected, shouldn't it?
However, the AsyncTask still working and eventually callbacks on onPostExecute.
One of my guesses is that it creates a thread and that thread has a reference to the object. As soon as the thread dies, the AsyncTask is also garbage collected.
Is my guess any close to the actual answer?
0 comments:
Post a Comment