By assigning view controllers that hit the stack to a strong instance variable / property, they will not be freed when removed from the stack. Strong properties hold onto pushed view controllers even after they slip out of the stack, so they never end up in a state in which they can be freed.
Usually I do something like the following when you push the next level view controller down on the navigation stack:
SLSMoleculeSearchViewController *searchViewController = [[SLSMoleculeSearchViewController alloc] initWithStyle:UITableViewStylePlain]; [self.navigationController pushViewController:searchViewController animated:YES];
In ARC, the new view controller will be highlighted and saved at creation. When you click on the navigation stack, it will be held once by the navigation controller. Since this new view controller is not mentioned after clicking and is not bound to a strong property or instance variable, ARC will release it after the second line.
Remember that it is still stored by the navigation controller, so it still lives in memory. However, as soon as the navigation controller pushes it from the stack, this controller will be freed. Since nothing is holding at this moment, it will be released as expected.
If for some reason you need to maintain a link to this subview controller in your higher level view controller, you can use the weak property or the __weak instance __weak . This will not be held by the view controller and will be turned off when the controller is released.
weak links are only supported for apps targeting iOS 5.0, so you won’t be able to do this for something that needs to be run on iOS 4.0. The 4.0 compliant unsafe_unretained property unsafe_unretained not something I would recommend in this case because of the danger of a pointer to freed memory.
source share