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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:37:08+00:00 2026-06-17T07:37:08+00:00

Although I’ve solved this problem. I really need someone to explain to me why

  • 0

Although I’ve solved this problem. I really need someone to explain to me why it worked.

I’ve got a UINavBar that has a custom UIView as the visible ViewController. I created a custom button in place of the navbar’s title view and set it as autorelease (I’m customising existing non-ARC code):

- (void)loadView {
    ..  

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button addTarget:self
               action:@selector(presentEmailThreadList)
     forControlEvents:UIControlEventTouchDown];
    [button setTitle:[NSString stringWithFormat:@"1 of %d",self.numThreads] forState:UIControlStateNormal];
    button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);

    self.navigationItem.titleView = [button autorelease];
}

This code works when I present a view modally ie:

[self presentModalViewController:emailThreadListVC animated:YES];

but gives me an EXC_BAD_ACCESS error if I try to push it to the navigation stack, then click the ‘back button’ on the new VC:

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

and specifically crashes at the UINavigationItemTitleView:

enter image description here

I’ve concluded that the titleView no longer exists when I try to go back to the original VC, meaning that the autorelease did decrement the reference count on the titleView when I push a VC ontop the stack, but it won’t decrement the reference count when I push a VC modally.

Any idea why?

  • 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-06-17T07:37:10+00:00Added an answer on June 17, 2026 at 7:37 am

    The problem is here:

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    ...
    self.navigationItem.titleView = [button autorelease];  <-- DOUBLE AUTORELEASE
    

    buttonWithType already returns an autoreleased object, so you do not need to explicitly autorelease it again.

    Why it works when you use presentViewController is another issue. I think it comes down to different timings in the two cases.

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

Sidebar

Related Questions

although this question sound noob.. but i really need to know this. What is
Although I should really know this, I am afraid that I don't get it
Although appengine already is schema-less, there still need to define the entities that needed
Although I have found some solutions to this problem, none of them refer to
Although this has been discussed many times here in Stackoverflow, I couldn't get the
Although this question is asked before, my problem is little different. I have a
although this C++ compiler error has been reported many times, I did not find
Although it seems like a simple problem, I have really come up empty on
Although I know that there are more idomatic ways of doing this, why doesn't
Although this issue has been brought up in the past, I'm curious if this

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.