rhormaza
rhormaza

Reputation: 507

releasing UIViewControllers

I am using 3 UIViewControllers in my app and now I am wondering if it is a good idea to release them when I switch from to another. Obviously, it would be the hidden ones which I really dont need them while they are not visible... to switch views, I'm using something like this (uiwindow):

//this is in the first UIViewController
[[[UIApplication sharedApplication] keyWindow] addSubview:secondController.view];
[self.view removeFromSuperview];
//here I release the view controller
[self release];

So my question...it's that really worth it? what could be the performance issues?

Also, I would like to ask if someone knows why these lines work in this order (see below). I tried the other way around and I have problems with the orientation which stopped to work? any hints?

//working
[[[UIApplication sharedApplication] keyWindow] addSubview:secondController.view];
[self.view removeFromSuperview];

//not working
[self.view removeFromSuperview];
[[[UIApplication sharedApplication] keyWindow] addSubview:secondController.view];

Thanks

Raul

Upvotes: 2

Views: 284

Answers (1)

EmptyStack
EmptyStack

Reputation: 51374

... it's that really worth it? what could be the performance issues?

You can very well release a view controller once you added it as subview of another view(a superView), in which case the superView retains the subview. [[UIApplication sharedApplication] keyWindow] is the superView of secondController.view and it retains secondController.view. So, that is a correct way to do it and it won't cause any performance issues.

Upvotes: 1

Related Questions