I need to understand what is happening in terms of memory in this situation. Am I correct in assuming that when using the addSubView method that view retains the new view and then when calling the removeFromSuperView the retain count by that superview is reduced to zero (eventually)?
I am creating a view like this:
homeViewController = [[HomeViewController alloc]init]; //self retain count = 1
[self.view addSubview:homeViewController.v开发者_如何学Pythoniew]; //self retain count = 1; self.view retain count = 1
I am removing the view like this:
[homeViewController.view removeFromSuperview]; //self retain count = 1; self.view retain count = 0
When you do the addSubview, it retains the view, so you could autorelease it if you didn't want to track when it was not being used anymore.
HomeViewController
is also retaining the view because it is the view's controller. Thus, the view won't be destroyed unless the controller is released as well.
精彩评论