0

I am presenting a view controller programmatically onto a navigation controller, and I discovered that after popping (if pushed) or dismissing (if modal) the presented view controller, it doesn't deallocate the view controller and is still retained by the navigation controller.

What is the proper way to ensure that a programmatically presented view controller will NOT be retained by the navigation controller and will deallocate once it is popped/dismissed?

MyNewViewController *myNewViewController = (MyNewViewController*)[[UIStoryboard storyboardWithName:@"MyNewViewController" bundle:nil] instantiateInitialViewController];
[self.navigationController presentViewController:myNewViewController animated:YES completion:nil];
JimmyJammed
  • 9,598
  • 19
  • 79
  • 146
  • 1
    It should be deallocated whether you dismiss or pop. There must be some object still holding a strong reference to this controller. You need to show what you're doing in MyNewViewController. – rdelmar Feb 21 '15 at 02:57
  • What do you mean, "discovered..."? If you send the pop message to the nav controller and dismiss message to the presenting view controller, unless you are retaining it yourself somewhere, it's gone. Note: a navigation controller specifically pushes/pops, but any view controller can present. – Mike Sand Feb 21 '15 at 02:59
  • The 'dealloc' function in MyNewViewController is never called. Also, I am adding notification observer in that controller's 'viewDidLoad', and now notice that it added multiple observers, as the function it calls gets called however many times I displayed (then popped and re-displayed) the view. – JimmyJammed Feb 21 '15 at 21:56

0 Answers0