I upload multiple images to a ListView using AsyncTask. It looks something like this:
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, the garbage collector collects everything that is not referenced anymore.
Since the stack pointer leaves the function above, the class loses any references to the created ImageViewLoader. It should be garbage collection then, right?
However, AsyncTask still works and ultimately turns to onPostExecute.
One of my assumptions is that it creates a stream, and that stream has an object reference. As soon as the thread dies, AsyncTask also collects garbage.
I believe that is close to the actual answer?