Is the UIViewController calling the method presentViewController removed from the memory?
ios, memory-management, uistoryboard, uiviewcontroller
Solution
When you use the `presentViewController:animated:completion:` method from controller `A` to present controller `B` modally, what happens is that the `presentedViewController` property of `A` is set to controller `B`, and the `presentingViewController` property of `B` is set to `A`. Thus, both controllers are kept in memory while the presentation is taking place.
When you go from `B` to `A`, you call `dismissViewControllerAnimated:completion:` on `A` via the `presentingViewController` property of `B`, like this:
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
(You can also call `[self dismissViewControllerAnimated:YES completion:nil]` and the system will automatically forward the request to the presenting view controller.)
After that, the `presentedViewController` property of `A` will be set to `nil` and, consequently, it will be subject to memory deallocation by the system, provided that there isn't any other strong pointer pointing to it.
Problem
Supposedly I have a UIViewController A and a UIViewController B. From A, I call the method presentViewController:B. When B shows up, what happens to A? Is it removed from the memory? If not, what method should I call to delete it? If my UI flow is like this, A->B->A->B->A->B->... and so on, how to prevent the memory from increasing accordingly?