Skip to content

Flow as environmentObject causes memory leak #6

Closed

Description

@metallica1375

Hey I think I found a big issue about the whole concept of using the flow as an environmentObject. when you pass the flow as @EnvironmentObject private var object: FlowProvider the swiftUI holds it in the whole app and none of the view models of any nested screens would get destroyed after the related screen get poped and also for the screens that you hold in the NavigationController stack.
For Example If I start from the home screen and go to the details screen, the view model of the home screen remains alive and also after I pop from the details screen back to the home screen the view model of the details screens remains alive.

public var body: some View {
    flow.present()
      .environmentObject(flow)
  }

Activity

  1. mercen-lee commented on Jun 22, 2026

    @mercen-lee
    Owner

    Resolved in 86cdb21 on main.

    FlowKit no longer injects FlowProvider as a SwiftUI EnvironmentObject. @Flow now reads a weak custom environment value, and FlowPresenter plus pushed hosting controllers apply that value automatically, avoiding the provider-retains-navigation-stack-retains-environment cycle.

    Validation: xcodebuild -scheme FlowKit -destination "generic/platform=iOS Simulator" -sdk iphonesimulator build succeeded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions