I have an application with many views. Whenever I click the next button on the first view I present the second view. Currently I am doing this as follows:
NextView *second = [[NextView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
In this application, however, I don’t need to keep any information from the first view any more. Is there some way I can bring up the second view, and deallocate the first view from memory? I was thinking that if I bring up 5 views in a row, and all of them are modal, then I will be using more memory that I really need. If the user hits the back button, I would also like to open the first view, and remove the second from memory.
Is there some way to do this to save memory, or is this memory just something I should not worry about?
You should definitely try to use
UINavigationController. WithpushViewController:animated:you push a new view controller on the stack, and you get a navigation bar with a “Back” button for free. WithpopToViewController:animated:you can go back to the initial view controller.UINavigationControlleris very well documented and there are lots of sample programs. I haven’t used Storyboard yet, but that should make it even simpler to build a navigation controller based sequence of views.You need not care about releasing the views from memory. Views are unloaded automatically if memory is low. If your view controller allocates huge amounts of additional memory, then you should implement
didReceiveMemoryWarningto release that memory. See The View Controller Life Cycle for details.