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

  • Home
  • SEARCH
  • 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 7001661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:49:55+00:00 2026-05-27T20:49:55+00:00

Consider the following two allocations of arrays. NSMutableArray* alpha = [[[NSMutableArray alloc] init] autorelease];

  • 0

Consider the following two allocations of arrays.

NSMutableArray* alpha = [[[NSMutableArray alloc] init] autorelease];

NSMutableArray* beta = [NSMutableArray array];

Assuming nothing else retains alpha or beta, my understanding is that the result of both is the same. The retain count on both will 0 and therefor they will be cleared up once they leave scope.

I have a sneaking suspision that I am not fully grasping the subtle implications between the two. After reading a StackOverflow answer I know the latter is a convenience method, but I would like to understand the differences.

What is the difference between the two lines of codes above in regards to memory management?

  • 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-27T20:49:55+00:00Added an answer on May 27, 2026 at 8:49 pm

    Those two lines are equivalent. In both cases objects are created that you have a reference to but not an owning reference. However, they’ll be on the autorelease pool. That means they’ll last as long as the pool does, which if you’ve not done anything special will be until control returns to the run loop. Objects like that therefore (usually) survive beyond their scope — that’s useful because it means you can (and usually do) provide autoreleased objects as return results.

    The rule is that methods that return an object but do not contain ‘new’, ‘alloc’, ‘retain’ or ‘create’ in their name will return an autoreleased object. That’s the logic behind +array returning an autoreleased object.

    As an aside: if you enable ARC then autoreleased objects will still be returned but the compiler may be smart enough to take them out of the autorelease pool (which is something you can’t do manually) and release them manually in a calling method where it won’t affect program flow.

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

Sidebar

Related Questions

Consider the following two ways of writing a loop in Java to see if
Consider the following two alternatives: console.log("double"); console.log('single'); The former uses double quotes around the
Consider the following two Java files that contain a simplified version of my issue
Do splitting fields into multiple tables ever yield faster queries? Consider the following two
I'm a bit puzzled about the conditional operator. Consider the following two lines: Float
Let's consider the two following lines in C# (using framework .NET 3.5) Regex regex
Consider the following situation: We have two Localizable.string files, one in en.lproj and one
Consider the following .Net ASMX web service with two web methods. using System; using
Consider the following example. It consists of two header files, declaring two different namespaces:
Consider the following example. I have an interface MyInterface, and then two abstract classes

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.