-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WeakReference on Target #83
Comments
Use |
I just ran into this issue as well. Providing a strong reference to the Target fixed the problem for me. |
This one just got me too (using the latest code from master). I'm loading larger images and using Picasso's resize(), to scale them down. I think this is resulting in an immediate GC by the vm, clearing the weak ref to my Target. I'm not sure the proper usage of fetch() in this case, I want to get a callback when it's complete. I've resorted to maintaining a strong reference to the Target object myself, but it feels dirty. |
|
Unless it's changed recently, I don't think the loaded Bitmap is passed as
|
That's by design. It's to take action when an image is loaded (e.g., animate the view) not touch the Bitmap. Implement |
It's not "dirty" at all. Keeping the reference around will also allow you to call If Picasso maintained a strong reference to your target it would eventually leak your context until the download was complete.
|
Oh nice. When should you call cancelRequest(Target)?
|
You should call cancelRequest when a Target (e.g. a custom View) requests a new image. This will let picasso cancel an old request if it's not yet executed. |
But only if you are not in a list/grid adapter! Requesting an image for the same imageview/target (e.g., in an adapter getView) will do this automatically. You should only need to cancel (and you don't actually need to) if you're making requests and then leaving the screen. |
…k reference of the targets used to get the bitmaps. With this approach our new targets instances was being garbage collected. We've reduced the number of allocations and the number of targets created using an array of NoxItemCatalogImageLoaderListener and using a WeakHashMap to keep the target instances. THIS BUG WAS VERY INTERESTING TO FIX square/picasso#83
Hi.
I had a strange-not-always-appearing bug.
Finally, I found it was because of using WeakReference on
public void into(Target target) {
makeTargetRequest(target, false);
}
I was using this method with an inner class. Something like
.load(xx).into(new Target() {
});
And as Picasso doesn't keep references on it, it was sometimes garbage collected before the image is downloaded.
Having a weakreference on an ImageView make sense but on a Target, I'm not sure.
It needs more work from the developper to keep a strong reference somewhere else to a target object he doesn't really care about.
I'm not afraid Piasso keeps a strong reference on this object until the request is done and the callback called.
Mike
The text was updated successfully, but these errors were encountered: