Skip to content
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

Bitmap recycling not implemented #114

Closed
dominolog opened this issue Jul 5, 2013 · 4 comments
Closed

Bitmap recycling not implemented #114

dominolog opened this issue Jul 5, 2013 · 4 comments

Comments

@dominolog
Copy link

From what I can see the library does not provide recycling of Bitmap objects. I miss a class extending ImageView that does that. Any chance for adding support for that?

@JakeWharton
Copy link
Member

Recycling requires much more infrastructure than that. You have to keep reference counts manually and recycle when it returns to zero. That becomes increasingly hard to do when we expose the raw Bitmap through the Target interface for custom views to implement. Consumers would have to manage incrementing and decrementing the reference count themselves. Considering most don't even use the Target interface correctly I don't think many would use reference counts correctly either.

Additionally, we keep an LRU cache of Bitmap instances for quick loads of the most used images. We can't even recycle when a Bitmap is purged from the LRU because there is no guarantee that it still isn't being used on the screen.

There's simply too much going on to recycle explicitly. We defer to appropriately sized memory caches and the normal garbage collector for this.

@dominolog
Copy link
Author

I agree with the fact that recycling would require more effort on writing extra code. I do not agree with the fact that reference counting must be done by consumer code. It is fairly easy to implement a Bitmap recycler. It must extends ImageView and override onDetachedFromWindow method. Also, the overloaded ImageView class must be aware of cache object and correctly dereference the contained Bitmap from the cache when being destroyed.
I could take care of such an implementation, I have done it for one of my project. It would be really valuable to have it in Picasso because without it, the Picasso library is only useful for loading small thumbnail bitmaps. For larger, full screen images (for tablets) it goes really quickly into OOM which can't be handled by user easily.

@JakeWharton
Copy link
Member

The whole point of the memory cache is to keep images when they are not being displayed, not remove them. This allows quick subsequent loads of the same image.

If you are loading full-screen bitmaps for display once you should try the skipCache option.

@jiqimaogou
Copy link

in android 2.3, if do not call recycle, is it memory leak?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants