0

I have two views (as in full screens, view controllers) in my iOS Swift application, lets call them view A and view B.

View A is a menu that will open View B when you press a button. View B displays images one at the time and will eventually go back to View A.

View B is opened when you press a button in view A. It is opened using an IB show segue. View A is opened again using a method call to:

let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("<name here>")
self.presentViewController(viewController, animated: true, completion: nil)

If I go through the loop of opening View B looking at all the pictures then through View A to B again an so on, the memory usage will just continue to increase. I though that the ARC system would get rid of such old views but that seems to not be the case. What is the correct way to avoid this?

Alex
  • 731
  • 1
  • 11
  • 24
  • I think this is happening because your view controller B is not getting destroyed. Check if there is any strong relationship between VC A & B. Generally, this type of issue caused due to string relationship in both view controllers. Or paste some code? – Kumar Aug 09 '16 at 10:09
  • how about add self.dismissViewControllerAnimated(true, completion: nil) in viewB willDisappear? – Willjay Aug 09 '16 at 10:11
  • I also think that View B is not getting destroyed but I kinda don't have control over how it is being created and displayed since it is opened using IB. I will try dissMissViewControllerAnimated(true, completion: nil). – Alex Aug 09 '16 at 10:15
  • Thank you very much, using: dissmissViewControllerAnimated(true, completion: nil) instead of the code from the post works very well. However, I had to remove a segue show from the Storyboard and replace it with an action method and then call dissmissViewControllerAnimated from there. Is it not possible to avid this using IB segues? – Alex Aug 09 '16 at 10:26
  • See linked duplicate question. If you want to use segues, then you need to use an *unwind segue* which returns to the calling ViewController instead of creating a new one. – vacawama Aug 09 '16 at 10:47

0 Answers0