Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.
This repository was archived by the owner on Nov 1, 2022. It is now read-only.

Memory leak in consumeFlow if fragment is removed before flow is created #9056

@csadilek

Description

@csadilek

This is similar to #9017, except in this case the leak happens if the fragment is removed before the coroutine (that creates the flow) is launched: https://github.com/mozilla-mobile/android-components/blob/master/components/lib/state/src/main/java/mozilla/components/lib/state/ext/Fragment.kt#L92

We have introduced a check to make sure the fragment isn't destroyed when the flow is produced in #9019, which in theory should have taken care of this, but when fragments are removed their lifecycle is set back to initialized: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-master-dev:fragment/fragment/src/main/java/androidx/fragment/app/Fragment.java;l=2156?q=Fragment ...so it's possible that the fragment is destroyed and removed before this block even launches. We then create a subscription for a fragment that is already removed (its lifecycle.currentState being INITIALIZED) and we will never unsubscribe.

This leak can now be reproduced with the latest changes to SearchDialogFragment in Fenix. STR are mozilla-mobile/fenix#13785.

The simplest solution is to apply the same fix we did for #9017 here as well i.e. create an observer to make sure we notice when the fragment gets destroyed and do nothing / don't create the flow when the coroutine launches.

┆Issue is synchronized with this Jira Task

Metadata

Metadata

Assignees

Labels

<state>Component: browser-state🐞 bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions