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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:55:16+00:00 2026-05-14T00:55:16+00:00

The more I code, the more I get lost … so I decided to

  • 0

The more I code, the more I get lost … so I decided to create a topic entirely dedicated to the memory management for me (and others) not to waste hours understanding obj-c basics … I’ll update it as new questions are asked !

Okay below is some examples :

// myArray is property (retain)
myArray = otherArray;

//myArray isn't a property
myArray = otherArray;

//myArray is a property (retain)
myArray = [[NSArray alloc] init];

//myArray isn't a property
myArray = [[NSArray alloc] init];

— So, if I understand … when you put self.myArray you tell Xcode to use the getter or setter but when you just do myArray, you are responsible for everything, right ?

[SOLVED] UPDATE1 : Is there a difference between :

//myArray is a property
myArray = otherArray; // it is only a reference, releasing otherArray will imply releasing myArray
self.myArray = otherArray; // otherArray is sent a retain message so releasing otherArray will still keep myArray in memory

— Yes, there is a difference (see comments above)

[SOLVED] UPDATE2 : Is myArray below equal to nil ?

NSArray *myArray;

— Kubi : Yes, it is equal to nil.

[SOLVED] UPDATE3 : does it count for 2 retains ? One retain from self and one retain from alloc ? Is this a memory leak ?

self.myArray = [[NSArray alloc] init];

— Kubi : Yes, this is a memory leak !

[SOLVED] UPDATE4 : the property takes care of everything ? no need to alloc or release ?

self.myArray = [NSArray array];

— We here use the setter so that the array is retained properly

[SOLVED] UPDATE5 : Are these two blocks the same ?

//myArray is a retained property

self.myArray = [NSArray array]; //retain
self.myArray = nil; //release and set to nil

myArray = [[NSArray alloc] initWithArray]; //retain
self.myArray = nil; //release and set to nil

— Kubi : Yes, they’re identical

Thanks for the time.

Gotye.

  • 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-14T00:55:17+00:00Added an answer on May 14, 2026 at 12:55 am

    First, I’m assuming that you have a property called myArray and an iVar called myArray? If so, cases 1,2 are identical and 3,4 are identical. If you need to set a property of your current class, you must do it through one of the following methods:

    self.myArray = otherArray;
    [self setMyArray:otherArray];
    

    the line myArray = otherArray will only set the iVar, never the property.

    Second part, you’re asking about memory management. Step one: read Apple’s Guide. It really is required reading. Don’t worry if you don’t completely understanding, keep reading it once a month and it’ll crystalize eventually.

    Step two: remember this rule of thumb: If you alloc, copy, new, or retain an object, you are responsible for releasing that object, if you don’t, it will be leaked.

    In all other cases, you are not responsible for releasing the object, but it will be released eventually. If you need to keep it around, you need to retain it (and, of course, release it later).

    Back to your example, in the first two cases, if you don’t retain myArray it’ll be released at some point after this code block. If you try and message that object later, you’ll get an error. In the second two cases, if you don’t release the myArray object at some point, it will be leaked.


    Update 1
    Very big difference. The two lines are completely different. The important thing to realize about dot syntax is that these two lines are exactly equivalent:

    self.myArray = otherArray;
    [self setMyArray:otherArray];
    

    Notice the second line is a method call. Theoretically you could put anything you wanted in that method. You could set myArray to nil, or set it to someOtherArray, or update twitter or whatever.


    Update 2
    Yup, pointers in Obj-C are initialized to nil.


    Update 3
    Exactly. If the myArray property is declared as retain and you’re using the default synthesizers you will be causing a memory leak.

    Update 5
    Also exactly right.

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

Sidebar

Ask A Question

Stats

  • Questions 370k
  • Answers 370k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer GCC and MSVC use #import for different things. In GCC,… May 14, 2026 at 6:45 pm
  • Editorial Team
    Editorial Team added an answer 1. Constant extrapolation You can use interp function from scipy,… May 14, 2026 at 6:45 pm
  • Editorial Team
    Editorial Team added an answer you can use the load() callback function like this: $("#myDiv").fadeOut().load("www.someurl.com",… May 14, 2026 at 6:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.