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

Fixes leak when calling destroyOnDetach from onDetachedFromWindow. #1100

Conversation

rjrjr
Copy link
Contributor

@rjrjr rjrjr commented Aug 7, 2023

View.isAttachedToWindow returns false while the view is dispatching calls to onDetachedFromWindow. As a result, calling WorkflowLifecycleOwner.destroyOnDetach from an onDetachedFromWindow handler that was downstream of its own would mean that the WLO would never get destroyed.

Also makes DialogSession.destroyDialog idempotent. Necessary because ComponentDialog.dismiss() is not, and with this fix we are more likely to call that redundantly.

(The actual culprit is ComponentDialog.onStop(), which nulls out ComponentDialog._lifecycleRegistry. The second call to that method creates a new instance on demand as a side effect to its call to handleLifecycleEvent, which immediately throws due to an illegal transition from INITIALIZED to DESTROYED. Tried to rely on just checking Dialog.isShowing before calling dismiss(), but that's not reliable.)

`View.isAttachedToWindow` returns false while the view is dispatching calls to `onDetachedFromWindow`. As a result, calling `WorkflowLifecycleOwner.destroyOnDetach` from an `onDetachedFromWindow` handler that was downstream of its own would mean that the WLO would never get destroyed.

Also makes `DialogSession.destroyDialog` idempotent. Necessary because `ComponentDialog.dismiss()` is not, and with this fix we are more likely to call that redundantly.

(The actual culprit is `ComponentDialog.onStop()`, which nulls out `ComponentDialog._lifecycleRegistry`. The second call to that method creates a new instance on demand as a side effect to its call to `handleLifecycleEvent`, which immediately throws due to an illegal transition from `INITIALIZED` to `DESTROYED`. Tried to rely on just checking `Dialog.isShowing` before calling `dismiss()`, but that's not reliable.)
@rjrjr rjrjr marked this pull request as ready for review August 8, 2023 16:45
@rjrjr rjrjr requested review from zach-klippenstein and a team as code owners August 8, 2023 16:45
@rjrjr rjrjr force-pushed the ray/fix-WorkflowLifecycleOwner-destroyOnDetach-from-onDetach-leak branch from 7f2197a to 45f02b7 Compare August 8, 2023 16:47
@rjrjr rjrjr merged commit 99ea9b7 into main Aug 8, 2023
@rjrjr rjrjr deleted the ray/fix-WorkflowLifecycleOwner-destroyOnDetach-from-onDetach-leak branch August 8, 2023 20:08
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

Successfully merging this pull request may close these issues.

2 participants