I have created a simple flow to test memory in ios app. I have two view controllers in a navigation stack. I am showing an alert in the first view controller to allow user to move to the next one. Following is the code I am using.
class ViewController: UIViewController {
@IBOutlet weak var labelInfo: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func showNextScreen(_ sender: Any) {
let alert = UIAlertController(title: "Alert", message: "Go to next screen?", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: { [unowned self] (action) in
self.performSegue(withIdentifier: "showNextScreen", sender: nil)
}))
alert.addAction(UIAlertAction(title: "No", style: .default, handler: { [unowned self] (action) in
self.labelInfo.text = "You did not move to next screen"
alert.dismiss(animated: true, completion: nil)
}))
self.present(alert, animated: true, completion: nil)
}
}
Having gone through the resources mentioning that there should not be a strong reference cycle, I have used unowned self in the code. Checking the leaks in the Instruments, I got the following graph.
The graph shows no leaks as indicated by green tick marks. However, as I move back and froth between the two view controllers, the memory usage graph is being increased. What might be causing this increase in memory usage (first question)?
Next, I also checked the effects replacing unowned self with self. The result I got is the same as before. This suggests there is no strong reference. How do we determine existence of strong retain cycle with reference to this example (second question)?