Do init* functions retain what is passed to them?
-
21-09-2019 - |
Question
I init a navigation controller with:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
I wonder if the navigation controller retains firstViewController or that I need to keep it alive. When I release firstViewController, the navigation controller still works. That seems wrong.
Clarifications?
Solution
If it needs to keep it around it will retain
it. So yeah, you'll be safe to release it if you don't need it anymore. It's not just initWhatever
methods that have this behaviour - it's the standard operation of the whole memory management model.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow