What happens after a viewController is placed in another viewController

I was just interested in programming. I have a rootViewController that instantiates childViewController. This childVC is being pushed into my rootViewController via [self.navigationController pushViewController: childVC] from another childViewController (say childVC2). Now I was wondering what was going on with my childVC2 instance. Does it come out? Because when returning from childVC to childVC2, I create a new instance of childVC2 and insert it into my rootViewController. Obviously I am not using an earlier instance of childVC2 and what is going on with it, or can I manually release it?

+3


source to share


1 answer


Yes, if you allocate the ViewController, you should release it. push will increase the link count by 1, so you have to be sure to pop it to decrease the link count .. and to instantiate it, define it in .h, and when you instantiate it, do it like this:

if(yourViewController)
  [yourViewContoller release];

yourViewController = [yourViewControllerClass alloc] init];

      



another way is to make it auto-advertise, in which case you are not responsible for releasing the ViewController

yourViewController = [yourViewControllerClass alloc] init]autorelease];

      

+1


source







All Articles