Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory management with tabBarController #7

Open
MIP9 opened this issue Jun 1, 2018 · 1 comment
Open

Memory management with tabBarController #7

MIP9 opened this issue Jun 1, 2018 · 1 comment

Comments

@MIP9
Copy link

MIP9 commented Jun 1, 2018

Hi there!
In #4 you show how to use coordinators with tabBarController. But what if I want to go back from tabBarController? My code:

`
class TabCoordinator: BaseCoordinator {

  let startNavigationController: UINavigationController

  init(navigationController: UINavigationController) {
    self.startNavigationController = navigationController
    self.startNavigationController.navigationBar.isHidden = true
  }

  override func start()-> Observable<Void> {
    let rootTabBarController = TabBarViewController.initFromStoryboard(name: "Main")

    let viewControllers = initControllers()

    let homeCoordinator = HomeCoordinator(rootViewController: viewControllers[0])
    coordinate(to: COHomeCoordinator)
      .subscribe()
      .disposed(by: disposeBag)

    let profileCoordinator = ProfileCoordinator(rootViewController: viewControllers[1])
    coordinate(to: profileCoordinator)
      .subscribe()
      .disposed(by: disposeBag)

    let logout = HomeCoordinator.logoutUser!

    /*
    In HomeCoordinator I have 
    let logoutUser: PublishSubject<Void>!
    that bind to logout button.
    */

    rootTabBarController.viewControllers = viewControllers
    rootTabBarController.tabBar.isTranslucent = false
    startNavigationController.pushViewController(rootTabBarController, animated: true)
    return logout.do(onNext: {[weak self] _ in
      self?.startNavigationController.popViewController(animated: true)
    })
  }

  private func initControllers()->[UINavigationController]{
    let homeVC = UINavigationController()
    homeVC.tabBarItem = UITabBarItem(title: "Home", image: nil, selectedImage: nil)

    let profileVC = UINavigationController()
    profileVC.tabBarItem = UITabBarItem(title: "Profile", image: nil, selectedImage: nil)

    return [homeVC, profileVC]
  }
}

`

The problem is that I have growing memory when login-loguot few times. I have tried set coordinators to nil in return block, but it does not work.

@shabirjan
Copy link

Did you try removing coordinators from ChildCoordinator Array? Were you able to fix that memory leak issue? @MIP9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants