RxFlow: Memory leak when ending .multiple flow

My app currently has a serious memory leak and I was able to reproduce it in a slightly modified version of the demo app.

It is demonstrated in this branch: https://github.com/wberger/RxFlow/tree/test/multiple_leak

The relevant files are: RxFlowDemo/RxFlowDemo/Flows/AppFlow RxFlowDemo/RxFlowDemo/Flows/DashboardFlow RxFlowDemo/RxFlowDemo/Flows/WishlistFlow

I added a “Logout” button to the wishlist. Hitting this button will trigger a step in WishlistStepper, which in turn ends the WishlistFlow. This ends the parent (= DashboardFlow) and triggers a navigation to the OnboardingFlow from within the AppFlow.

The problem is that only WishlistFlow reaches deinit, while DashboardFlow and WatchedFlow don’t. As a result the whole UITabbarController and all contained ViewControllers are kept.

Reentering the DashboardFlow from onboarding creates new instances while the old dashboard flows and view controllers are kept thus creating a potentially huge memory leak.

I had a quick look at the Flow implementations but wasn’t able to find the error. But in general, when a flow ends, the ending flow and all sub flows have to be released.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 5
  • Comments: 37 (6 by maintainers)

Most upvoted comments

Hi guys

Very interesting. Thanks for the example. I will work on that ASAP.

@twittemb Thank you, this fixes the issue!

I had the same issue and solved it by the simple but hacky solution to remove all VCs in the tab bar on .end.

The latest commit in the develop branch fixes this issue for me.

Thx!

Hi there.

I’m working on RxFlow 2.0.0. It brings some breaking changes and a refactor of the memory management. I think it can address the issues that are exposed in this thread.

It would be great if you could give me your feedback on this version (it is currently on the develop branch)

Here are the changes:

  • Coordinator has been renamed in FlowCoordinator.
  • NextFlowItem and NextFlowItems have been renamed in FlowContributor and FlowContributors.
  • The FlowContributors enum entry .end (withStepForParentFlow: Step) has been renamed in .end (forwardToParentFlowWithStep: Step).
  • The FlowContributor class has been converted to an enum with the following entries: .contribute(withNextPresentable: Presentable, withNextStepper: Stepper), .forwardToCurrentFlow(withStep: Step) and .forwardToParentFlow(withStep: Step). It allows to unify the way we can contribute to a Flow.
  • In an effort to minimize the usage of objc_get/setAssociatedObject, each custom Stepper must declare a stored property steps as a PublishSubject.
  • To trigger an initial Step inside a Stepper, an initialStep property has to be implemented. A default implementation is provided by RxFlow if it makes no sense to emit a first Step for your specific use case. This default implementation emits a “void step” that will be ignored by the Flow.
  • The reactive step property of a Stepper has been renamed in steps to reflect the plurality of the sequence of steps it can emit.
  • FlowCoordinator has been totally rewritten to improve memory management.
  • HasDisposeBag has been removed from the project as it was not mandatory in the implementation and is not really related to RxFlow. A similar implementation can be found in NSObject-Rx.
  • The RxFlowStep enum is now provided to offer some common steps that can be used in lots of applications. This enum will grow in size over time.
  • Some of the old data structure names are still usable but have been explicitly deprecated.

The demo app has been adapted to all those changes.

@dsk1306 There was an issue with my release. Please try again by reinstalling the v1.6.2.

Thanks.

Same issue here

Hi there.

May I close this issue since there hasn’t been any comment about memory leaks for a while now ?

Thanks.

Hi guys,

RxFlow 2.0.0 “Enterprise” is released 🎉.

@twittemb haven’t found any bugs during testing. Can’t wait for version 2.0 😃

@twittemb I would like to take a look)

Hi there. Is there anyone who is willing to test RxFlow 2.0.0 before the release ?

Hi there

I’m on vacation for a few days, i will have finally the time to give some love to RxFlow and bring you some answers.

Stay tuned.

hi @twittemb, thanks for the fix. However, I notice this fix is working on Carthage but CocoaPods. I have same set of code, both are using v1.6.2, but CocoaPods seems still leaking memory.

CocoaPods: https://github.com/fatbunboy/RxFlowTestingPods

Carthage: https://github.com/fatbunboy/RxFlowTesting

Thank you, I will try it tomorrow!