1

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!

1 Answer 1

1

If the user toggles back and forth from your RootViewController to a NextViewController repeatedly, here's what happens:

  1. The NextViewController is created (alloc'd) in your didSelectRowAtIndexPath: method. Because you called an init method on it, you're responsible for releasing it.
  2. You push nextView onto the navigation controller stack, which retains it.
  3. You release nextView, so the only thing with a retain on it is the navigation controller.
  4. Once your user moves back from the NextViewController, the navigation controller releases it. Now nothing is retaining 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.