My app has the following layout/flow:
LandingVC: The page a new user will see when first runs the app. This page will explain what the app is for and has 2 buttons: Login and Register
LoginVC: Where the user will use his/her email and password to log in
RegisterVC: Where the user will use his/her email and password to register
MainVC: A tab bar view controller where the user will be redirected if:
- user registers successfully for the first time
- user logs in successfully
- user is logged in
If the user is not logged in he/she should be redirected to LandingVC.
The way I am handling it is as follows:
In appDelegate.swift I check whether the user is logged in or not.
If the user is logged in I set the MainVC as the root controller.
If the user is not logged in, then i set the LandingVC as the root controller.
QUESTION A: Everything work just fine but since I am fairly new to iOS development I worry if the way I present/push/dismiss ViewControllers is the correct one in terms of memory consumption and code efficiency. What do you think? Do I get it all wrong or am I in the right path?
To measure it I followed the procedure below:
Run the app in iOS Simulator using iPhone X. The user is initially not logged in so I used the same flow 3 times: LandingVC --> LoginVC --> MainVC.
The results below:
ps1: to get the results I used the "Debug Navigator" tab in xCode.
To verify that no ViewController was dismissed during the whole flow I used the "View Memory Graph Hierarchy":
As you can see we have 3 instances of every ViewController I navigated through (by the way, MainVC is the MainTabBarController which is consisted of HomeViewController, FavouritesViewController, TrendingViewController, and SettingsViewController).
QUESTION B: Is there a way I can deallocate [remove/pop/dismiss/etc] ViewControllers from memory but still have the same result?
QUESTION C: Is it normal for the memory to increase from 55.4 MB to 68.1 MB following that flow?
ps2: All UI was built programmatically. No Storyboard involved.
Thanks in advance and sorry for the long post.