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

IllegalStateException: Cannot obtain size for recycled Bitmap #2574

Closed
Thrakbad opened this issue Nov 7, 2017 · 30 comments
Closed

IllegalStateException: Cannot obtain size for recycled Bitmap #2574

Thrakbad opened this issue Nov 7, 2017 · 30 comments
Labels
Milestone

Comments

@Thrakbad
Copy link

Thrakbad commented Nov 7, 2017

Hi,
we recently updated our app from Glide 3.7.0 to Glide 4.1.1. In the new release, we are getting some Crashes in our Crashlogger with the following Stacktrace:

Stack trace / LogCat:

Fatal Exception: java.lang.IllegalStateException: Cannot obtain size for recycled Bitmap: android.graphics.Bitmap@7e65b27[450x450] ARGB_8888
       at com.bumptech.glide.util.Util.getBitmapByteSize(SourceFile:73)
       at com.bumptech.glide.load.engine.prefill.BitmapPreFillRunner.allocate(SourceFile:115)
       at com.bumptech.glide.load.engine.prefill.BitmapPreFillRunner.run(SourceFile:132)
       at android.os.Handler.handleCallback(Handler.java:815)
       at android.os.Handler.dispatchMessage(Handler.java:104)
       at android.os.Looper.loop(Looper.java:207)
       at android.app.ActivityThread.main(ActivityThread.java:5710)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)

So far all of the crashes are on devices running Android 6.0. Do you have any hints what I should look for to find what's causing this issue?

@sjudd
Copy link
Collaborator

sjudd commented Nov 7, 2017

Unfortunately it can be a challenge to track these errors down.

A few things to check are listed here: https://github.com/bumptech/glide/wiki/Resource-re-use-in-Glide#causes

@Thrakbad
Copy link
Author

Thrakbad commented Nov 8, 2017

Is this link still valid, because at the top of the page it says it covers Glide 3 only? We have upgraded to Glide 4, we did not have this issue with Glide 3.7.0.

@sjudd
Copy link
Collaborator

sjudd commented Nov 8, 2017

That page is pretty much the same for v3 and v4. I haven't had the chance to write the v4 equivalent yet, though when I do, it'll probably mostly be a copy/paste.

@sjudd sjudd added the question label Nov 9, 2017
@stale
Copy link

stale bot commented Nov 16, 2017

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

@stale stale bot added the stale label Nov 16, 2017
@Kevinrob
Copy link

I have a similar bug after upgrading from v3 to v4 with a simple GlideApp.with(this).load(url).into(image_view) 😞
OS: Android 7.0

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)
[...]

Maybe it's a bug with the LruCache? Race condition?

@stale stale bot removed the stale label Nov 23, 2017
@Thrakbad
Copy link
Author

So far I haven't found a single thing that could cause this in our code. We are not using custom Bitmap transforms or anything where we would be recycling Bitmaps on our own.

@sjudd
Copy link
Collaborator

sjudd commented Nov 23, 2017

Are you able to reproduce this reliably? Or is this something you see in crash logs?

@Thrakbad
Copy link
Author

We are not able to reproduce this reliably. We see it in our crashlogger. In the last 24 hours it happened 23 times for 7 users. All running Android 6. This is with >100k daily active users, so it is by no means a huge issue, but still the crash we see most often.

@sjudd
Copy link
Collaborator

sjudd commented Nov 23, 2017

And is it always that same stack trace? Originating from the prefiller?

@Thrakbad
Copy link
Author

Yes. The bitmap size in the exception message differs, that depends on the screen size. I can't imagine that matters, though. the trace is the same.

@sjudd sjudd added bug and removed question labels Nov 23, 2017
@sjudd
Copy link
Collaborator

sjudd commented Nov 27, 2017

@Kevinrob

I think I've found a way to reproduce @Thrakbad's issue, but I'm not sure yours is related. If you're not using the prefill APIs, please file a new issue.

@sjudd sjudd added this to the 4.4 milestone Nov 27, 2017
@sjudd
Copy link
Collaborator

sjudd commented Nov 27, 2017

@Thrakbad the exception is actually happening in Glide's debug logging here:

.getConfig() + " size: " + Util.getBitmapByteSize(bitmap));
.

You might want to strip Log.d/Log.v from your release apks.

I have a fix for the issue anyway that I'll push shortly.

@Thrakbad
Copy link
Author

Great, thanks a lot. We will try that in our next release.

@sjudd sjudd closed this as completed in 7387298 Nov 27, 2017
@VolodymyrMachekhin
Copy link

VolodymyrMachekhin commented Dec 26, 2017

Hello! We suffered from the issue after upgrade from v 4.3.1 to 4.4.0
Fatal Exception: java.lang.IllegalStateException: Cannot obtain size for recycled Bitmap: android.graphics.Bitmap@b8f2509[512x512] ARGB_8888 at com.bumptech.glide.util.Util.getBitmapByteSize(Util.java:74) at com.bumptech.glide.load.resource.bitmap.BitmapResource.getSize(BitmapResource.java:52) at com.bumptech.glide.load.engine.EngineResource.getSize(EngineResource.java:57) at com.bumptech.glide.load.engine.cache.LruResourceCache.getSize(LruResourceCache.java:39) at com.bumptech.glide.load.engine.cache.LruResourceCache.getSize(LruResourceCache.java:13) at com.bumptech.glide.util.LruCache.trimToSize(LruCache.java:179) at com.bumptech.glide.util.LruCache.evict(LruCache.java:187) at com.bumptech.glide.util.LruCache.put(LruCache.java:140) at com.bumptech.glide.load.engine.cache.LruResourceCache.put(LruResourceCache.java:13) at com.bumptech.glide.load.engine.Engine.onResourceReleased(Engine.java:327) at com.bumptech.glide.load.engine.EngineResource.release(EngineResource.java:109) at com.bumptech.glide.load.engine.Engine.release(Engine.java:287) at com.bumptech.glide.request.SingleRequest.releaseResource(SingleRequest.java:343) at com.bumptech.glide.request.SingleRequest.clear(SingleRequest.java:322) at com.bumptech.glide.request.ThumbnailRequestCoordinator.clear(ThumbnailRequestCoordinator.java:133) at com.bumptech.glide.manager.RequestTracker.clearRemoveAndMaybeRecycle(RequestTracker.java:72) at com.bumptech.glide.manager.RequestTracker.clearRemoveAndRecycle(RequestTracker.java:59) at com.bumptech.glide.RequestManager.untrack(RequestManager.java:579) at com.bumptech.glide.RequestManager.untrackOrDelegate(RequestManager.java:547) at com.bumptech.glide.RequestManager.clear(RequestManager.java:535) at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:588) at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:640)

@sjudd
Copy link
Collaborator

sjudd commented Dec 27, 2017

@VolodymyrMachekhin That's a different stack trace, please file a new issue if you'd like help.

@utkarshGithub
Copy link

any solutions?

@Goorwl
Copy link

Goorwl commented Nov 19, 2018

opps,without any solution still Nov 19th 2018?

@alienwings
Copy link

opps,without any solution still Jun 20th 2019?
ps: I use glide 4.9.0

@timhuang1018
Copy link

similar problem at version 4.9.0 , but can't reproduce crash again

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.timhuang.iifrienddebugrev, PID: 13894
java.lang.IllegalStateException: Cannot obtain size for recycled Bitmap: android.graphics.Bitmap@ccba2e4[2160x3840] ARGB_8888
at com.bumptech.glide.util.Util.getBitmapByteSize(Util.java:78)
at com.bumptech.glide.load.resource.bitmap.BitmapResource.getSize(BitmapResource.java:55)
at com.bumptech.glide.load.engine.EngineResource.getSize(EngineResource.java:60)
at com.bumptech.glide.load.engine.cache.LruResourceCache.getSize(LruResourceCache.java:42)
at com.bumptech.glide.load.engine.cache.LruResourceCache.getSize(LruResourceCache.java:13)
at com.bumptech.glide.util.LruCache.put(LruCache.java:124)
at com.bumptech.glide.load.engine.cache.LruResourceCache.put(LruResourceCache.java:13)
at com.bumptech.glide.load.engine.Engine.onResourceReleased(Engine.java:322)
at com.bumptech.glide.load.engine.EngineResource.release(EngineResource.java:113)
at com.bumptech.glide.load.engine.Engine.release(Engine.java:286)

@Mouadabdelghafouraitali
Copy link

@timhuang1018 I have similar issue here, have you solved it?

@ngallazzi
Copy link

ngallazzi commented Oct 18, 2019

In my case the problem was I was calling bitmap.recycle() on the image loaded with Glide. After removing recycle call the error vanished ;)

@sumitsahoo
Copy link

Same issue here :(

java.lang.IllegalStateException: Cannot obtain size for recycled Bitmap: android.graphics.Bitmap@15ebd4c[893x403] ARGB_8888
        at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4604)
        at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4622)
        at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:39)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1916)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6898)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

@Esioner
Copy link

Esioner commented Dec 6, 2019

I had the same problem,it‘s caused by i used glide download bitmap and i call Bitmap.recycle() method. After removing this calling , i am not repeat this problem

@sumitsahoo
Copy link

getBitmapPool() needs to be called inside a if check !bitmap.isRecycled() because when you see the actual method description it does call recycle() hence resulting crash.

@mariuspena
Copy link

has this been fixed ?

@Livekus
Copy link

Livekus commented Apr 23, 2020

Glide.with(mContext).clear(imageView);
// clear bitmap from image view here

@AndxEng
Copy link

AndxEng commented Aug 1, 2020

I had the same prolem at version 4.11.0

Caused by java.lang.IllegalStateException
Cannot obtain size for recycled Bitmap: android.graphics.Bitmap@f7f6ca1[1200x576] ARGB_8888
com.bumptech.glide.util.Util.getBitmapByteSize (Util.java:79)
com.bumptech.glide.load.resource.bitmap.BitmapResource.getSize (BitmapResource.java:52)
com.bumptech.glide.load.engine.EngineResource.getSize (EngineResource.java:62)
com.bumptech.glide.load.engine.cache.LruResourceCache.getSize (LruResourceCache.java:40)
com.bumptech.glide.load.engine.cache.LruResourceCache.onItemEvicted (LruResourceCache.java:11)
com.bumptech.glide.util.LruCache.put (LruCache.java:117)
com.bumptech.glide.load.engine.cache.LruResourceCache.put (LruResourceCache.java:11)
com.bumptech.glide.load.engine.Engine.onResourceReleased (Engine.java:396)
com.bumptech.glide.load.engine.EngineResource.release (EngineResource.java:116)
com.bumptech.glide.load.engine.Engine.release (Engine.java:362)
com.bumptech.glide.request.SingleRequest.clear (SingleRequest.java:326)
com.bumptech.glide.manager.RequestTracker.clearAndRemove (RequestTracker.java:72)
com.bumptech.glide.RequestManager.untrack (RequestManager.java:663)
com.bumptech.glide.RequestManager.untrackOrDelegate (RequestManager.java:631)
com.bumptech.glide.RequestManager.clear (RequestManager.java:627)
com.bumptech.glide.RequestManager.onDestroy (RequestManager.java:374)
com.bumptech.glide.manager.ActivityFragmentLifecycle.onDestroy (ActivityFragmentLifecycle.java:65)
com.bumptech.glide.manager.SupportRequestManagerFragment.onDestroy (SupportRequestManagerFragment.java:215)

@LoggerWang
Copy link

do not recycle the resource bitmap in onResourceReady()
@Override public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) { //do not do this: resource.recycler() //and not do like this: //var bitmap = resource //.... bitmap.recycler() }

it is useful for me

@zhouzhuo810
Copy link

do not recycle the resource bitmap in onResourceReady()
@Override public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) { //do not do this: resource.recycler() //and not do like this: //var bitmap = resource //.... bitmap.recycler() }

it is useful for me

我也是在onResourceReady里面将Bitmap回收了导致的。

@ali-imran
Copy link

I am facing this issue
Exception java.lang.RuntimeException:
at android.app.ActivityThread.performDestroyActivity (ActivityThread.java:4589)
at android.app.ActivityThread.handleDestroyActivity (ActivityThread.java:4611)
at android.app.servertransaction.DestroyActivityItem.execute (DestroyActivityItem.java:39)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState (TransactionExecutor.java:145)
at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1861)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:193)
at android.app.ActivityThread.main (ActivityThread.java:6819)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:497)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:912)
Caused by java.lang.IllegalStateException:
at com.bumptech.glide.util.Util.getBitmapByteSize (Util.java:81)
at com.bumptech.glide.load.resource.bitmap.BitmapResource.getSize (BitmapResource.java:52)
at com.bumptech.glide.load.engine.EngineResource.getSize (EngineResource.java:62)
at com.bumptech.glide.load.engine.cache.LruResourceCache.getSize (LruResourceCache.java:40)
at com.bumptech.glide.load.engine.cache.LruResourceCache.getSize (LruResourceCache.java:11)
at com.bumptech.glide.util.LruCache.put (LruCache.java:131)
at com.bumptech.glide.load.engine.cache.LruResourceCache.put (LruResourceCache.java:11)
at com.bumptech.glide.load.engine.Engine.onResourceReleased (Engine.java:397)
at com.bumptech.glide.load.engine.EngineResource.release (EngineResource.java:116)
at com.bumptech.glide.load.engine.Engine.release (Engine.java:363)
at com.bumptech.glide.request.SingleRequest.clear (SingleRequest.java:345)
at com.bumptech.glide.manager.RequestTracker.clearAndRemove (RequestTracker.java:70)
at com.bumptech.glide.RequestManager.untrack (RequestManager.java:660)
at com.bumptech.glide.RequestManager.untrackOrDelegate (RequestManager.java:628)
at com.bumptech.glide.RequestManager.clear (RequestManager.java:624)
at com.bumptech.glide.RequestManager.onDestroy (RequestManager.java:371)
at com.bumptech.glide.manager.ActivityFragmentLifecycle.onDestroy (ActivityFragmentLifecycle.java:65)
at com.bumptech.glide.manager.RequestManagerFragment.onDestroy (RequestManagerFragment.java:210)
at android.app.Fragment.performDestroy (Fragment.java:2782)
at android.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1451)
at android.app.FragmentManagerImpl.moveFragmentToExpectedState (FragmentManagerImpl.java:1576)
at android.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1637)
at android.app.FragmentManagerImpl.dispatchMoveToState (FragmentManagerImpl.java:3046)
at android.app.FragmentManagerImpl.dispatchDestroy (FragmentManagerImpl.java:3026)
at android.app.FragmentController.dispatchDestroy (FragmentController.java:248)
at android.app.Activity.performDestroy (Activity.java:7394)
at android.app.Instrumentation.callActivityOnDestroy (Instrumentation.java:1306)
at android.app.ActivityThread.performDestroyActivity (ActivityThread.java:4574)

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

No branches or pull requests