Glide: IllegalStateException: Cannot obtain size for recycled Bitmap (LazyBitmapDrawableResource)

Created on 27 Nov 2017  路  6Comments  路  Source: bumptech/glide


Glide Version: 4.3.1


Integration libraries: OkHttp3


Device/Android Version: Nexus 5X


Issue details / Repro steps / Use case background:
GlideApp.with(this).load(url).into(image_view) in a RecyclerView within onBindViewHolder

Sometimes, I get:

Exception java.lang.IllegalStateException: Cannot obtain size for recycled Bitmap: android.graphics.Bitmap@237446a[1080x3641] ARGB_8888
com.bumptech.glide.util.Util.getBitmapByteSize (Util.java:74)
com.bumptech.glide.load.resource.bitmap.LazyBitmapDrawableResource.getSize (LazyBitmapDrawableResource.java:52)
com.bumptech.glide.load.engine.EngineResource.getSize (EngineResource.java:51)
com.bumptech.glide.load.engine.cache.LruResourceCache.getSize (LruResourceCache.java:37)
com.bumptech.glide.load.engine.cache.LruResourceCache.getSize (LruResourceCache.java:11)
com.bumptech.glide.util.LruCache.put (LruCache.java:121)
com.bumptech.glide.load.engine.cache.LruResourceCache.put (LruResourceCache.java:11)
com.bumptech.glide.load.engine.Engine.onResourceReleased (Engine.java:334)
com.bumptech.glide.load.engine.EngineResource.release (EngineResource.java:101)
com.bumptech.glide.load.engine.Engine.release (Engine.java:292)
com.bumptech.glide.request.SingleRequest.releaseResource (SingleRequest.java:337)
com.bumptech.glide.request.SingleRequest.clear (SingleRequest.java:316)
com.bumptech.glide.manager.RequestTracker.clearRemoveAndRecycle (RequestTracker.java:62)
com.bumptech.glide.RequestManager.untrack (RequestManager.java:462)
com.bumptech.glide.RequestManager.untrackOrDelegate (RequestManager.java:449)
com.bumptech.glide.RequestManager.clear (RequestManager.java:437)
com.bumptech.glide.RequestBuilder.into (RequestBuilder.java:574)
com.bumptech.glide.RequestBuilder.into (RequestBuilder.java:626)
[...]


Glide load line / GlideModule (if any) / list Adapter code (if any):

GlideApp.with(this).load(url).into(image_view)


Layout XML:

    <ImageView
        android:id="@+id/image_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"/>


Stack trace / LogCat:

Exception java.lang.IllegalStateException: Cannot obtain size for recycled Bitmap: android.graphics.Bitmap@237446a[1080x3641] ARGB_8888
com.bumptech.glide.util.Util.getBitmapByteSize (Util.java:74)
com.bumptech.glide.load.resource.bitmap.LazyBitmapDrawableResource.getSize (LazyBitmapDrawableResource.java:52)
com.bumptech.glide.load.engine.EngineResource.getSize (EngineResource.java:51)
com.bumptech.glide.load.engine.cache.LruResourceCache.getSize (LruResourceCache.java:37)
com.bumptech.glide.load.engine.cache.LruResourceCache.getSize (LruResourceCache.java:11)
com.bumptech.glide.util.LruCache.put (LruCache.java:121)
com.bumptech.glide.load.engine.cache.LruResourceCache.put (LruResourceCache.java:11)
com.bumptech.glide.load.engine.Engine.onResourceReleased (Engine.java:334)
com.bumptech.glide.load.engine.EngineResource.release (EngineResource.java:101)
com.bumptech.glide.load.engine.Engine.release (Engine.java:292)
com.bumptech.glide.request.SingleRequest.releaseResource (SingleRequest.java:337)
com.bumptech.glide.request.SingleRequest.clear (SingleRequest.java:316)
com.bumptech.glide.manager.RequestTracker.clearRemoveAndRecycle (RequestTracker.java:62)
com.bumptech.glide.RequestManager.untrack (RequestManager.java:462)
com.bumptech.glide.RequestManager.untrackOrDelegate (RequestManager.java:449)
com.bumptech.glide.RequestManager.clear (RequestManager.java:437)
com.bumptech.glide.RequestBuilder.into (RequestBuilder.java:574)
com.bumptech.glide.RequestBuilder.into (RequestBuilder.java:626)
[...]


Crashlytics link => http://crashes.to/s/c8f170b34a0

needs triage repro-needed

Most helpful comment

No problem, thank you for filling out the issue template and providing so much detail, it makes it much easier to suggest this kind of solution. I also very much appreciate the follow up, super helpful. Glad it's fixed.

All 6 comments

Are you calling recycle() on any Bitmaps loaded by Glide? It's unlikely that just calling into() in a RecyclerView with no other action is causing this.

If you find a way to reproduce this let me know and preferably add a failing test. Otherwise most of the suggestions for looking in to this are here: http://bumptech.github.io/glide/doc/resourcereuse.html#common-errors

Thanks for your reply. I found a call to Bitmap.recycle() on this ImageView.
Sorry. 馃槥

No problem, thank you for filling out the issue template and providing so much detail, it makes it much easier to suggest this kind of solution. I also very much appreciate the follow up, super helpful. Glad it's fixed.

I have the same error.
But I have not control on the call of Bitmap.recycle because it's passed to a custom ImageView (https://github.com/davemorrissey/subsampling-scale-image-view) that call it.

Is there a way to remove the Bitmap loaded by Glide from the BitmapPool management?
Otherwise the only other option would be to clone the full Bitmap (that come from Camera so it's huge).

UPDATE: The problem was not the recycle called the by the custom image viewer.
Glide 4.6.1

I don't know if open another bug, because not sure it is a bug.
Here my code, please someone tell me if it is the correct way to use BitmapPool or if there is something wrong.

First: Load the image in a Bitmap:
Glide. with(this). asBitmap(). load(imageUri). into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) { mPhotoBitmap = resource; doShowSaveImage(); } });

Then: allocate another image, some work, and recycle the first (no more need)

newBitmap = Glide.get(this).getBitmapPool().get(mPhotoBitmap.getWidth(), mPhotoBitmap.getHeight(), config ); // ... somework Glide.get(this).getBitmapPool().put( mPhotoBitmap ); mPhotoBitmap = newBitmap;

A the end of the Activity: recycle the image
Glide.get(this).getBitmapPool().put( mPhotoBitmap );

The problem DOES not happen if I comment BitmapPool.put() method.

Having this issue.
Have a way of reproducing it...
Happen when:
In an activity called X a recycler view with scrolling load many pictures.
Finish that activity and open activity B.
Finish activity B and open A and scroll in the recycler view.

W/Bitmap: Called getWidth() on a recycle()'d bitmap! This is undefined behavior!
W/Bitmap: Called getHeight() on a recycle()'d bitmap! This is undefined behavior!
W/Bitmap: Called getConfig() on a recycle()'d bitmap! This is undefined behavior!

Was this page helpful?
0 / 5 - 0 ratings