Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

How to free presenter manually / Nested fragments/presenter don't get destroyed #101

Open
ar-g opened this issue Jun 15, 2017 · 3 comments

Comments

@ar-g
Copy link

ar-g commented Jun 15, 2017

I have a situation when user switch fragments

  1. A -> B which contains nested fragment C
  2. user goes back from fragment B -> A, but C presenter retained in memory.

It happens many times and creates serious memory footprint. After 20 times or so the app may even freeze.

Basically when there is a check in onDestroy() isFragmentInBackstack() = false, but isFragmentRemoving() = false in nested fragment and nothing get cleared

How to free presenter manually in such case?

@ar-g
Copy link
Author

ar-g commented Jun 20, 2017

I found the way to solve it, but it is ugly. Now, presenters of nested fragments will free immediately. Better solutions are welcome

@Override public void onPause() {
    super.onPause();
    if (isRemoving() && !isFragmentInBackstack()) {
      if (nestedFragment != null) {   getChildFragmentManager().beginTransaction().remove(nestedFragment).commitNowAllowingStateLoss();
      }
    }
  }

@sbaar
Copy link

sbaar commented Aug 4, 2017

Can you explain what is causing the memory leak or churn? Are you saying multiple C presenters are being created? Is the B destroyed at the right time but not the C presenter?

@ar-g
Copy link
Author

ar-g commented Aug 5, 2017

B presenter is destroyed, but C presenter remains in memory. Because check isRemoving() && !isFragmentInBackstack() is not passing in C fragment.

@StefMa StefMa changed the title How to free presenter manually? How to free presenter manually / Issue with nested fragments Sep 29, 2017
@StefMa StefMa changed the title How to free presenter manually / Issue with nested fragments How to free presenter manually / Nested fragments don't get destroyed Sep 29, 2017
@StefMa StefMa changed the title How to free presenter manually / Nested fragments don't get destroyed How to free presenter manually / Nested fragments/presenter don't get destroyed Sep 29, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants