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 in OnDestroy() "Failed to remove target from managers" #2262

Closed
JustinTipton opened this issue Aug 18, 2017 · 15 comments
Closed
Labels
Milestone

Comments

@JustinTipton
Copy link

I am trying to migrate from v3 to v4 and I'm running into an error I cannot seem to solve. Perhaps it is a bug in 4.0

I have seven fragments containing list views, each is using Glide to load images, and all are tied to the same activity. I'm using "Glide.with(Fragment)" for each fragment.

In the activity onDestroy, I'm seeing the following crash, which is weird, because I've done my best to not call "Glide.with(Activity)". Either way, I wouldn't expect this exception.

Caused by: java.lang.IllegalStateException: Failed to remove target from managers
at com.bumptech.glide.Glide.removeFromManagers(Glide.java:639)
at com.bumptech.glide.RequestManager.untrackOrDelegate(RequestManager.java:426)
at com.bumptech.glide.RequestManager.clear(RequestManager.java:412)
at com.bumptech.glide.RequestManager.onDestroy(RequestManager.java:272)
at com.bumptech.glide.manager.ActivityFragmentLifecycle.onDestroy(ActivityFragmentLifecycle.java:64)
at com.bumptech.glide.manager.SupportRequestManagerFragment.onDestroy(SupportRequestManagerFragment.java:187)
at android.support.v4.app.Fragment.performDestroy(Fragment.java:2496)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1483)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1569)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1636)
at android.support.v4.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:3028)
at android.support.v4.app.Fragment.performDestroy(Fragment.java:2492)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1483)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1569)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1636)
at android.support.v4.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:3028)
at android.support.v4.app.FragmentController.dispatchDestroy(FragmentController.java:262)
at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:390)
at android.support.v7.app.AppCompatActivity.onDestroy(AppCompatActivity.java:209)

@sjudd
Copy link
Collaborator

sjudd commented Aug 18, 2017

Do you see this every time your Activity is destroyed? Or only sometimes?

If you could reproduce this in a sample app it would be much easier for me to investigate. I agree this crash shouldn't happen.

@sjudd sjudd added the bug label Aug 18, 2017
@JustinTipton
Copy link
Author

I did not see this every time the activity was destroyed. I do believe it is a race condition.

Unfortunately, I am pressed for time and just reverted to the old version of Glide I was using.

@JustinTipton
Copy link
Author

JustinTipton commented Sep 7, 2017

I updated to Glide 4.1.1 today, just to test if this is fixed. Unfortunately, I still get a crash with v4. Not the same one though.

java.lang.IllegalStateException: Already released
at com.bumptech.glide.util.pool.StateVerifier$DefaultStateVerifier.throwIfRecycled(StateVerifier.java:44)
at com.bumptech.glide.load.engine.EngineJob.addCallback(EngineJob.java:98)
at com.bumptech.glide.load.engine.Engine.load(Engine.java:186)
at com.bumptech.glide.request.SingleRequest.onSizeReady(SingleRequest.java:436)
at com.bumptech.glide.request.target.ViewTarget$SizeDeterminer.getSize(ViewTarget.java:209)
at com.bumptech.glide.request.target.ViewTarget.getSize(ViewTarget.java:67)
at com.bumptech.glide.request.SingleRequest.begin(SingleRequest.java:242)
at com.bumptech.glide.manager.RequestTracker.resumeRequests(RequestTracker.java:95)
at com.bumptech.glide.RequestManager.resumeRequests(RequestManager.java:234)
at com.bumptech.glide.RequestManager.onStart(RequestManager.java:257)
at com.bumptech.glide.manager.ActivityFragmentLifecycle.onStart(ActivityFragmentLifecycle.java:50)
at com.bumptech.glide.manager.SupportRequestManagerFragment.onStart(SupportRequestManagerFragment.java:175)
at android.support.v4.app.Fragment.performStart(Fragment.java:2369)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1458)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:700)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

@assassinshadow0
Copy link

any fixes for this?

@sjudd
Copy link
Collaborator

sjudd commented Oct 28, 2017

Let me know if you find a way to reproduce it.

@jonasborggren
Copy link

jonasborggren commented Oct 31, 2017

I get the java.lang.IllegalStateException: Already released on 4.2.0. No way to reproduce it. My users are the only ones who get it.

@acvt007
Copy link

acvt007 commented Nov 2, 2017

I have issue same jonasborggren with version 4.2.0

java.lang.RuntimeException: 
  at android.app.ActivityThread.performDestroyActivity (ActivityThread.java:3753)
  at android.app.ActivityThread.handleDestroyActivity (ActivityThread.java:3771)
  at android.app.ActivityThread.access$1700 (ActivityThread.java:139)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1308)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:136)
  at android.app.ActivityThread.main (ActivityThread.java:5294)
  at java.lang.reflect.Method.invokeNative (Native Method)
  at java.lang.reflect.Method.invoke (Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:864)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:680)
  at dalvik.system.NativeStart.main (Native Method)
Caused by: java.lang.IllegalStateException: 
  at com.bumptech.glide.Glide.removeFromManagers (Glide.java:656)
  at com.bumptech.glide.RequestManager.untrackOrDelegate (RequestManager.java:432)
  at com.bumptech.glide.RequestManager.clear (RequestManager.java:418)
  at com.bumptech.glide.RequestManager.onDestroy (RequestManager.java:279)
  at com.bumptech.glide.manager.ActivityFragmentLifecycle.onDestroy (ActivityFragmentLifecycle.java:64)
  at com.bumptech.glide.manager.SupportRequestManagerFragment.onDestroy (SupportRequestManagerFragment.java:187)
  at android.support.v4.app.Fragment.performDestroy (Fragment.java:2609)
  at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1557)
  at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState (FragmentManager.java:1740)
  at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1809)
  at android.support.v4.app.FragmentManagerImpl.dispatchStateChange (FragmentManager.java:3217)
  at android.support.v4.app.FragmentManagerImpl.dispatchDestroy (FragmentManager.java:3208)
  at android.support.v4.app.Fragment.performDestroy (Fragment.java:2604)
  at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1557)
  at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState (FragmentManager.java:1740)
  at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1809)
  at android.support.v4.app.FragmentManagerImpl.dispatchStateChange (FragmentManager.java:3217)
  at android.support.v4.app.FragmentManagerImpl.dispatchDestroy (FragmentManager.java:3208)
  at android.support.v4.app.FragmentController.dispatchDestroy (FragmentController.java:262)
  at android.support.v4.app.FragmentActivity.onDestroy (FragmentActivity.java:350)
  at android.support.v7.app.AppCompatActivity.onDestroy (AppCompatActivity.java:209)
  at online.daily.reader.activities.MainActivity.onDestroy (MainActivity.java:661)
  at android.app.Activity.performDestroy (Activity.java:5551)
  at android.app.Instrumentation.callActivityOnDestroy (Instrumentation.java:1120)
  at android.app.ActivityThread.performDestroyActivity (ActivityThread.java:3740)

@christophereluc
Copy link

christophereluc commented Nov 3, 2017

I encountered the first crash (Caused by: java.lang.IllegalStateException: Failed to remove target from managers) earlier today when migrating some code from 4.0 to 4.3. I think I narrowed it down to some code paths (in the same activity) that were either calling Glide.with(ApplicationContext) and Glide.with(ActivityContext). Having them both use the same context fixed that crash.

@sjudd
Copy link
Collaborator

sjudd commented Nov 13, 2017

@JustinTipton and @jonasborggren that's a different issue than the one reported here, please file a new issue.

@sjudd
Copy link
Collaborator

sjudd commented Nov 13, 2017

@acvt007 are you using a retained fragment?

@acvt007
Copy link

acvt007 commented Nov 13, 2017

Yes, i use retained fragment.

@sjudd
Copy link
Collaborator

sjudd commented Nov 13, 2017

Thanks, and @JustinTipton same question, in your original report were you using a retained fragment?

@sjudd
Copy link
Collaborator

sjudd commented Nov 13, 2017

I'll also try one more time with a retained fragment myself. If anyone has a reproducible case of this they can share, especially a sample app, I'd appreciate it.

If anyone who can reproduce this could share their Glide load line(s) that would help too (and any custom Target implementations).

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

sjudd commented Nov 17, 2017

The crash is fixed by 8119837, but anyone experiencing this crash has another bug and/or memory leak.

If you're seeing this crash it means that you have a case where you're starting a request with a RequestManager whose Activity or Fragment has already been destroyed. That could happen if you pass a RequestManager into an AsyncTask or other background thread. It could also happen if you reference the Activity RequestManager in a retained Fragment (via Glide.with(getContext()) or Glide.with(getActivity())).

This change will prevent this particular crash, but we may add an assertion here to make it clear that it's unsafe to start loads on destroyed RequestManagers in a future version of Glide.

@sjudd sjudd closed this as completed Nov 17, 2017
@NicolasGodfather
Copy link

Bug still reproducing in v4.9.0 - how fix it??? In my case I have 3 fragments(F1, F2, F3) in my activity (A1). Glide load urls in items of recyclerview in F2. Crash happens when backpressed from F3->F2->F1->exit from app. It seem a long bug in glide since v4.

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

7 participants