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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:53:49+00:00 2026-05-12T06:53:49+00:00

What reasons are there for doing in three lines what could be done in

  • 0

What reasons are there for doing in three lines what could be done in one?

Here is some code from developer.apple.com:

UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];

self.navigationController = aNavigationController;

[aNavigationController release];

…and the same thing in one line:

self.navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];

It seems clean, simple, and straightforward enough. I’ve had trouble in the past with a property not being retained, causing [object release] to destroy the object when it wasn’t supposed to (so far as I could tell – the retain attribute was set). Using the one-line formula works like a dandy.

  • 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-12T06:53:49+00:00Added an answer on May 12, 2026 at 6:53 am

    The Objective-C memory management rules dictate that by allocing an object instance you are a (shared once other objects retain it) owner of that instance and so you must release the UINavigationController when you want to relinquish ownership to prevent a memory leak. In a non-garbage collected environment (e.g. on the iPhone) this means balancing alloc or copy (or methods that contain “alloc” or “copy”) with release or autorelease. Your second snippet would then be

    self.navigationController = [[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease];
    

    If you can avoid using autorelease on a memory-limited environment (like the iPhone), it’s better to use explicit release. -[NSObject autorelease] adds the receiver to the current NSAutoreleasePool which will subsequently call -release on the objects in the pool ‘some time in the future.’ When you want to be careful about memory usage, ‘some time in the future’ is not a good idea. Thus, on the iPhone your first example is the standard usage.

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

Sidebar

Related Questions

Are there any good reasons to modify your project's build output path from its
There are many security reasons why one would want to drop an HTTP connection
Have you ever obfuscated your code before? Are there ever legitimate reasons to do
Is this possible? Given that C# uses immutable strings, one could expect that there
I have some complicated C++ code but the problem narrows down to doing a
Is there any reasons why PHP's json_encode function does not escape all JSON control
I want to store short arrays in a field. (I realize there are reasons
Are there any good reasons for why you would include JavaScript like this: <script
There are a lot of reasons for sound not work (no speakers, speakers turned
I know there are LOTS of reasons why you would compose a certain object

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.