Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6206325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:25:51+00:00 2026-05-24T05:25:51+00:00

navigationController = [[[UINavigationController alloc] initWithRootViewController:firstMenuView] autorelease]; [view addSubview:navigationController.view]; Does view keep a retain on

  • 0
navigationController = [[[UINavigationController alloc] initWithRootViewController:firstMenuView] autorelease];
[view addSubview:navigationController.view];

Does view keep a retain on navigtioncontroller? Or do I need to retain it?

Does calling navcontroller.view removefromparent actually release the nav controller?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:25:51+00:00Added an answer on May 24, 2026 at 5:25 am

    The controller is the owner of the view, the view will keep a weak reference (non-retained) to the controller, the controller will keep a strong (retained) reference to the view. In this case, your navigationController has been autoreleased, so it should theoretically end up deallocated, as long as nobody else retained it.

    The navigationController’s view on the other hand has been added as a subview to another, which means it is retained by the parent view. This is a problem, because if the view has any calls to the controller, those calls will go to a deallocated object.
    99% of the time you get EXC_BAD_ACCESS for this, and your app crashes. The other 1% is much worse.

    Fortunately though, all you need to do to prevent the above mentioned disasters is find something to “own” your navigation controller, give it a @property (retain) and assign your navigation controller to that. (Keep the autorelease, that part is good)
    Good candidates to own your navigation controller are the view controller of the parent view, and the application delegate.

    This way, the controller will stick around as long as it is needed, because it will have been retained at least once.

    What’s important here is the distinction between the controller and the view. The view object is retained, the controller object is alloc’d then autoreleased, so it’s gone unless you retain it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my app delegate I do this: navigationController = [[[UINavigationController alloc] initWithRootViewController:homePageController] autorelease]; [tabBarController
I init a navigation controller with: UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; I wonder
view1 = [[View1 alloc] init]; //Create the first view UINavigationController *navigationController1 = [[UINavigationController alloc]
I am using UINavigationController to push and pop a view. I used [[self navigationController]
The code: UIViewController *viewController = [[UIViewController alloc] initWithNibName:@NibName bundle:nil]; UINavigationController *navigationController = [[UINavigationController alloc]
At the end of this code: UIViewController *viewController = [[UIViewController alloc] init]; UINavigationController *navigationController
Given the UINavigationController delegate methods: -(void)navigationController:(UINavigationController*)navigationController (will/did)ShowViewController:(UIViewController*)viewController animated:(BOOL)animated How do you tell or compare
When I open MapView with navigationcontroller in a new view, then not waiting till
How should I go about creating a NavigationController for use in a view-based application?
I need some help to find a View inside a hierarchy. Here is how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.