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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:59:35+00:00 2026-06-02T16:59:35+00:00

This is a basic question, and I’m not really sure what to search for

  • 0

This is a basic question, and I’m not really sure what to search for to see if its been asked before.

In a lot of examples, I’ve seen property assignments handled like this:

NSArray *tempArray = [/*some code to get array*/];
self.propertyArray = tempArray;
[tempArray release];

Why not just do:

self.propertyArray = [/*some code to get array*/];

What’s the difference between the two?

  • 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-02T16:59:37+00:00Added an answer on June 2, 2026 at 4:59 pm

    This answer is assuming your not using ARC.

    The first code snippet, is the way Apple recommends initializing a property as long as you are doing this in any method besides init. You’ll notice Apple code snippets do this a lot. It makes it much easier to manage your memory, and in my opinion it makes it easier to read.

    NSArray *tempArray = [[NSArray alloc] initWith....]
    self.propertyArray = tempArray;
    [tempArray release];
    

    The second code snippet you have could potential lead to a memory leak depending how you set up the NSArray.

    This would be a leak. The propertyArray would have an retain count of 2. After you release the instance variable in dealloc, you still have a retain count of 1. That is a leak.

    self.propertyArray = [[NSArray alloc] initWith...];
    

    This would be okay, because they both are being autoreleased, which would give you a retain count of 1. As, long as you release the instance variable in dealloc.

    // Class Method so autoreleased
    self.propertyArray = [NSArray arrayWith....];
    
    // Explicitly declaring autorelease
    self.propertyArray = [[[NSArray alloc] initWith.....] autorelease];
    

    It’s simply just a matter of preference. I prefer the first way, I think it is easier to to read and follow.

    Edit (with ARC):

    All these methods would be acceptable with the exception of the release statement and autorelease statement.

    [tempArray release];
    

    ARC automatically takes care of the memory management for you, so you do not have to explicitly release them. This is the benefit of ARC, you can create as many objects as you want without the headache of trying to figure out where to release them.

    Also, your property would be different. You must either use strong or weak, and not retain. In this case strong would be the solution.

    @property (nonatomic, strong) NSArray *tempArray;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi this is a basic question, however I'm not sure about it, so I
Please do flog me for this really basic question, but I still can not
Maybe this is a basic question. but I still not sure jquery cookie ,
This seems a basic question I know but I've not been able to find
I realize this is a basic question but I have searched online, been to
G'day All, I am working in R. Sorry about this really basic question, but
This is a basic question but unfortunately I could not find the relevant command
This a very basic question but I've searched all over and been unable to
apologies if this is a basic question but I haven't been able to figure
this is basic question. im having touble setting the camra not how to set

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.