Search code examples
iosswiftapplication-lifecycle

Right view lifecycle when disconnecting


I have an app with a UITabBarController containing 5 items. In the last item (profile), the user can log out or delete his account and will be automatically redirected to the OnBoarding screen :

func signout(ofViewController sender: UIViewController, action: ENLoginScreenAction) {
    let onBoardingVC = ENOnBoardingViewController()
    onBoardingVC.withAction = action

    onBoardingVC.modalPresentationStyle = .formSheet
    ENUserInstance.userLogout()
    sender.present(onBoardingVC, animated: true)
}

I don't understand very well the UIView lifecycle notion so it appears that after logout, none of my 5 UITabBarController children are deinited.

I am pretty sure I am missing something about it so is there a way to deinit those children or is it normal to not do it after a logout or something similar in term of application lifecycle?


Solution

  • You right they are still here. And it's fine to have them there, as long as user can't access them if they are not supposed to. Don't worry about the memory, it's very light (depending actually on what you have in it). The os will deinit them if it considers that they are not useful anymore, which can be the case if they are not referenced anymore. Your tabbarcontroller might reference them, so that's maybe why they are not deinit