markcorn / libs-for-android

Automatically exported from code.google.com/p/libs-for-android
Apache License 2.0
0 stars 0 forks source link

Binding many ImageViews quickly causes most to be ignored #7

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create many ImageViews (more than the task limit).
2. Use an ImageLoader to bind each of them to different URLs.
3. Wait.

What is the expected output? What do you see instead?
In older versions of ImageLoader (somewhere pre-r125), all of the ImageViews 
would eventually load or error out using the ErrorCallback.

In the newest version, a few images get loaded or error and the rest never 
finish or call either callback.

What version of the product are you using? On what operating system?
Latest SVN version (r153) on Android 2.2.

Please provide any additional information below.
It looks like the thread/queue handling was redone in r125, and I don't think 
the new code works when binding many ImageViews in quick succession.

ImageRequest.execute() has a check to see if mCallbackRef is still valid, and 
short-circuits if not.  However, this WeakReference is to an ImageViewCallback 
created during the ImageRequest constructor, which clearly has no strong 
references, so of course it will get garbage collected.  When only a few 
ImageViews are bound at a time, the execution beats the garbage collector and 
works fine.  Or, in my case, when many ImageViews are bound, the first few 
succeed.  After that, the ImageViewCallbacks get GCed, and the execution of the 
remaining tasks gets aborted.

I assume the initial intention of this check was actually for a weak reference 
to the ImageView or Callback itself to see if they had been GCed, but creating 
a weak reference to a new object that points at them doesn't work.  Changing 
mCallbackRef to a normal reference fixes this issue completely.

Original issue reported on code.google.com by pipef...@gmail.com on 16 Jun 2011 at 1:54

GoogleCodeExporter commented 8 years ago

Original comment by pbald...@google.com on 16 Jun 2011 at 2:36