this is probably a newbie question…
I’m trying to reduce the amount of memory usage in my iPhone app.
I have an UIViewController with a set of buttons. When the user taps any of them, the app takes him to a new screen (new UIViewController).
Should I create them on demand ([[MyUIViewController alloc] initWithNibName:@”MyUIViewController” bundle:nil];), or should I have all these UIViewControllers as @propertys in the “main” controller, and create them only the first time? (check if they are nil).
I noticed (with Instruments) that, following the first approach, the used memory (Live bytes) increases on push but does not decrease when pulling the controller, and so on every time I press a button.
Furthermore, does that also applies to UITableViews, where I push another UIViewController in tableView:didSelectRowAtIndexPath: method?
Thank you in advance.
EDIT: I’m using ARC
Keeping them around and reusing them will keep your apps base memory at a higher level, but will probably increase the performance as these will not need to be recreated on demand.
That being said, the performance of pushing a new view controller is not very bad to begin with (unless you are doing something wrong) so just create them on demand.
If the old VC memory is not being released when popped, you might have a retain cycle somewhere. Look for any delegate code you may have written that is not getting cleared on the dismissal of the view.