-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
About bitmap recycle #687
Comments
@Caij Interesting question, did you have any problems or are you just trying to understand how it works? If a @sjudd Which brings me to something which I found by navigating the code:
So there are two things to consider: public void clearMemory() {
// ResourceRecycler.recycle asserts this anyway, fail faster and consistently
// (I think currently clearMemory would work on a background thread if there are no resources)
Util.assertMainThread();
// clear first so any pooled Bitmaps will be cleared as well
memoryCache.clearMemory(); // may return Bitmaps to pool
bitmapPool.clearMemory();
} All the above is based on static analysis, of course it would be nice to confirm this via debugging too. |
@TWiStErRob thanks. private EngineResource<?> getEngineResourceFromCache(Key key) {
Resource<?> cached = cache.remove(key);
final EngineResource result;
...
return result;
} I am very careless, wrong for cache.get(key). |
I double-checked it runtime and everything happens as predicted: Log.i("GLIDE", "Clearing memory cache");
Glide.get(this).clearMemory();
Log.i("GLIDE", "Clearing memory cache finished"); I/GLIDE﹕ Clearing memory cache
D/LruBitmapPool﹕ clearMemory
D/LruBitmapPool﹕ Evicting bitmap=[562800](RGB_565)
V/LruBitmapPool﹕ Hits=28, misses=16, puts=38, evictions=10, currentSize=0, maxSize=33177600
Strategy=SizeConfigStrategy{groupedMap=GroupedLinkedMap( {[1339200](RGB_565):0}, {[2048000](RGB_565):0} ), sortedSizes=(RGB_565[{}])}
-------------------- memoryCache.clearMemory() starts here ---------------------------
V/LruBitmapPool﹕ Put bitmap in pool=[1555200](RGB_565)
V/LruBitmapPool﹕ Hits=28, misses=16, puts=39, evictions=10, currentSize=1555200, maxSize=33177600
Strategy=SizeConfigStrategy{groupedMap=GroupedLinkedMap( {[1339200](RGB_565):0}, {[2048000](RGB_565):0}, {[1555200](RGB_565):1} ), sortedSizes=(RGB_565[{1555200=1}])}
V/LruBitmapPool﹕ Put bitmap in pool=[1339200](RGB_565)
V/LruBitmapPool﹕ Hits=28, misses=16, puts=40, evictions=10, currentSize=2894400, maxSize=33177600
Strategy=SizeConfigStrategy{groupedMap=GroupedLinkedMap( {[1339200](RGB_565):1}, {[2048000](RGB_565):0}, {[1555200](RGB_565):1} ), sortedSizes=(RGB_565[{1339200=1, 1555200=1}])}
V/LruBitmapPool﹕ Put bitmap in pool=[2048000](RGB_565)
V/LruBitmapPool﹕ Hits=28, misses=16, puts=41, evictions=10, currentSize=4942400, maxSize=33177600
Strategy=SizeConfigStrategy{groupedMap=GroupedLinkedMap( {[1339200](RGB_565):1}, {[2048000](RGB_565):1}, {[1555200](RGB_565):1} ), sortedSizes=(RGB_565[{1339200=1, 1555200=1, 2048000=1}])}
I/GLIDE﹕ Clearing memory cache finished What do you think @sjudd? |
@TWiStErRob Thanks。 I have understood. You are right. If a Bitmap is shown an ImageView it's an active resource, which means it's not in any cache or pool. |
What‘s the bug? |
Glide.clearMemory():
bitmapPool.clearMemory(); // all bitmaps are removed and recycled
memoryCache.clearMemory(); // all bitmaps are removed and put to pool?!
// end of clearMemory, but pool has stuff in it, so clear doesn't work as intended |
yep ,if call method in turn is right ?
|
Yup definitely a bug, we have the same issue in Glide 4: |
when LruMemoryCache full, LruMemoryCache remove some bitmap, these bitmap put BitmapPool , these bitmap reuse for other Bitmap Request。if these bitmap is using in ImageView,Will lead to errors?
The text was updated successfully, but these errors were encountered: