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 6255501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:22:36+00:00 2026-05-24T14:22:36+00:00

If I have a stack of views controlled by a view controller, and a

  • 0

If I have a stack of views controlled by a view controller, and a view’s dealloc (containing [super dealloc]) method is called when I pop the view from the view stack, does that mean I don’t have to release the view controller where it was created?

I ask because I originally was releasing the views after creation and pushing them to the navigation controller, except I continually get “overreleased” errors when I include [viewController release]. Without that statement, the navigation controller works fine, and the analyze function in XCode doesn’t complain about a potential memory leak.

Any sort of explanation would be greatly appreciated!

Edit: An example of where this occurs

 OnePlaceViewController *mapView = [[OnePlaceViewController alloc] initWithNibName:nil bundle:nil];

[self.navigationController pushViewController:mapView animated:YES];

Normally I would call [mapView release] after I push to the navigation controller (in my understanding of memory management, anyway), but I end up with a crash later in my app if I keep the line in there.

  • 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-24T14:22:37+00:00Added an answer on May 24, 2026 at 2:22 pm

    You never, ever call -dealloc directly. The only thing close is the call to [super dealloc], and that should only be called in your own dealloc. If you call dealloc directly, you should expect a crash later.

    If you meant to say [viewController release], then that indicates you have a mismatch somewhere of retains and releases. You should release what you retain. See Three Magic Words for more explanation and links to the full docs. They’re not hard, but you must follow them consistently.

    EDIT If you alloc, you should release when you’re done with the object. This doesn’t mean “when the object should be destroyed.” This means “when you are done with the object.” If other parts of the system still want the object, they’ll retain it. Retain what you want, release what you’re done with.

    In your example, you should release the mapView. You’ve handed it to the nav controller, and now you’re done with it. If you’re crashing in releasing it, you’re probably over-releasing somewhere else. The most likely place is one of OnePlaceViewController‘s ivars, or one of it’s owned-object’s ivars.

    Start with the static analyzer (Cmd-Shift-B in Xcode 4), and see if it finds your overrelease. It doesn’t do a good job of finding ivar overreleases, though. Then, make sure you always use accessors except in init and dealloc (and init is controversial). Accessing your ivars directly is the #1 cause of messed up memory management, which is the #1 cause of crashes.

    Do not just randomly insert and remove retains and releases. You will tie yourself up in knots. If you fix the crashes, you’ll leak. When you fix the leaks you’ll crash. You have to find the mistake and fix it. There’s no workaround until you upgrade to a system that includes ARC (at which point all of this magically goes away….)

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

Sidebar

Related Questions

I have a view controller that i'm trying to push onto the navigation stack.
Does anyone know if the problems that have been affecting Stack Overflow with regards
I have a view controller myViewController that makes HTTP requests. I set the request's
I have a Navigation Controller that is presented modally with 4 views in the
I have a stack panel inside of an expander panel that I programaticaly adds
I have read on Stack Overflow some people that have converting to C#2.0 to
I have a list of (64-bit) addresses that represent a stack frame, and I
I have a linker command file that assigns the top address of the stack
I have a view containing a UIWebView which is loading a google map (so
I have a view controller managed in a UINavigationController. My view controller puts up

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.