Reputation: 1384
First of all, sorry for my bad english. I'll try to explain my question:
I have a RootViewController (Navigation based project). So, it shows the tableview and when the user select a row of the table (didSelectRowAtIndexPath) y do the following to show the next view:
NextViewController *nextView = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
[self.navigationController pushViewController:nextView animated:YES];
[nextView release];
What happens if the user select the back button of the navigationbar and select again the row, and do this repeatedly? A lot of new views (instances of NextViewController) is being created (a lot of memory allocating)? Or is he just navigating the stack?
Can you help me? I dont want to waste memory in that way (if is the case). Thanks!
Upvotes: 1
Views: 1461
Reputation: 60110
If the user toggles back and forth from your RootViewController to a NextViewController repeatedly, here's what happens:
alloc
'd) in your didSelectRowAtIndexPath:
method. Because you called an init
method on it, you're responsible for releasing it.nextView
onto the navigation controller stack, which retains it.nextView
, so the only thing with a retain on it is the navigation controller.nextView
, so it gets dealloc
'd. The memory is freed.Basically, you do create a NextViewController every time your user moves back and forth (you're not "just navigating the stack," since objects are changing each time), but you're not leaking a large amount of memory or holding on to each controller you create. Your memory usage here is fine.
Upvotes: 1