Search code examples
iosxcodeuitableviewuinavigationcontrollerswift4

Navigation Controller (How to free memory when i press button "back")


Hello all :) i have question about a "navigation controller" i have structure INIT-> Navigation Controller -> View Controller (use Table View for output data from data) -> View Controller (go to from the selected cell and display data). I looked at the performance of the application and noticed that when i press button "back" and click at something data in table view and open again new view controller, Memory is increasing every time when i want look at data (i mean make a new view controller). The question: How to free memory?


Solution

  • Actually when you click back button the secondVC is automatically deallocated and you can verify that by logging in

    deinit{
      print("VC deallocated")
    }
    

    but this happens only if you don't have a strong reference to self and this occurs if you reference self inside a completion block , the view controller is being strongly referenced by some outside object or have a timer that you forget to invalidate when clicking back and many other cases