square / flow

Name UI states, navigate between them, remember where you've been.
Apache License 2.0
2.79k stars 241 forks source link

InternalLifecycleIntegration memory leak on P emulator #280

Open edenman opened 6 years ago

edenman commented 6 years ago
In co.recharge.consumer.debug:1.15.2:96.
* flow.InternalLifecycleIntegration has leaked:
* static FontsContract.sContext
* ↳ DebugConsumerApp.injectedAuthenticatedStuff
* ↳ ConsumerApp$InjectedAuthenticatedStuff.onSignedInHelper
* ↳ OnSignedInHelper.signInHooks
* ↳ array OnSignedIn[].[4]
* ↳ PlaceDirections.placeIDToDirectionsRelays
* ↳ LinkedHashMap.tail
* ↳ LinkedHashMap$LinkedHashMapEntry.value
* ↳ BehaviorRelay.state
* ↳ RelaySubscriptionManager.value
* ↳ RelaySubscriptionManager$State.observers
* ↳ array RelaySubscriptionManager$RelayObserver[].[0]
* ↳ RelaySubscriptionManager$RelayObserver.actual
* ↳ OperatorObserveOn$ObserveOnSubscriber.child
* ↳ OnSubscribeOnAssembly$OnAssemblySubscriber.actual
* ↳ SafeSubscriber.actual
* ↳ ActionSubscriber.onNext
* ↳ WalkingTimeView$setPlace$1.this$0 (anonymous implementation of rx.functions.Action1)
* ↳ WalkingTimeView.!(mContext)!
* ↳ FlowContextWrapper.!(mBase)!
* ↳ MainActivity.mFragments
* ↳ FragmentController.mHost
* ↳ Activity$HostCallbacks.mFragmentManager
* ↳ FragmentManagerImpl.mAdded
* ↳ ArrayList.elementData
* ↳ array Object[].[0]
* ↳ InternalLifecycleIntegration

A fun thing I learned today is that Flow uses Fragments for some reason? I'm looking at the InternalLifecycleIntegration code and I'm pretty much baffled by what's going on. Looks like it attaches a fragment to the Activity in onCreate, but then somehow FragmentManager is keeping a reference to it even after the activity has been destroyed?

LeakCanary 1.6.2, fwiw

Zhuinden commented 5 years ago

InternalLifecycleIntegration is a retained fragment, yes, but you're leaking the observers of * ↳ PlaceDirections.placeIDToDirectionsRelays yourself.

You need to unsubscribe your lambdas. Use composite disposables.