Release memory when returning in UINavigationController

0

I am building an application in swift 4.1 without using the storyboard. Basically in the appdelagate I create an instance of my main controller mainVC and add it to the root of my navigation controller

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    //inicializar la aplicación
    window = UIWindow(frame: UIScreen.main.bounds)

    let mainVC = MainVC()
    let navigationController = UINavigationController(rootViewController: mainVC)

    navigationController.setNavigationBarHidden(true, animated: true)
    window?.rootViewController = navigationController
    window?.makeKeyAndVisible()
    return true
}

Inside the mainVC I have a button that invokes a following viewer categoriesVC :

 @objc func goToCategories(){
    let categoriesVC = CategoriesVC()
    categoriesVC.view.backgroundColor = .cyan
    categoriesVC.title = "Categorías"
    categoriesVC.currentRegion = currentRegion

    navigationController?.setNavigationBarHidden(false, animated: true)
    navigationController?.pushViewController(categoriesVC, animated: true)
}

And once inside the categoriesCV controller that contains a tableView, I invoke a following controller that also contains a datatable subCategoriesVC .

I am observing that when I return to the first view categoriesCV and select the same option to go to the second subCategoriesVC controller, the use of the ram increases. Every time I perform this action of going back and then going forward, the RAM increases by 5 or 6 MB.

I am assuming that new instances of the drivers are created that will be presented each time and that are never released from memory. Is there any way to release the views that were loaded or tell the navigation controller that when it returns, remove the instances created from the views it loaded?

    
asked by Salvador Nava 11.06.2018 в 22:46
source

0 answers