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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:51:55+00:00 2026-06-18T07:51:55+00:00

I am new to iOS so trying to understand memory management. I have a

  • 0

I am new to iOS so trying to understand memory management.

I have a .h File which contains a property and i want to use that var in some function.

@property (nonatomic, retain) NSMutableArray *myArray;

then in my .m File i have some function x.

-(void) x
{
     // How to allocate memory to the property variable  ??

     _myArray = [NSMutableArray alloc]init];
OR
     myArray= [[NSMutableAraay alloc]init]


 // what is the utility of "_" here ?
}

and how to manage memory in this case as we have already used keyword Retain in .h file and also allocated memory in func x then how to do memory management.

In dealloc method

-(void)dealloc
{
[myArray release];
OR
[_myArray release];
// same here whats the difference B/W 2.?
[super dealloc];
}
  • 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-18T07:51:56+00:00Added an answer on June 18, 2026 at 7:51 am

    Using @property and @synthesize creates two methods, called accessors, that set and get a backing instance variable. The accessors are called either through normal method calls or dot notation (self.propertyname). The accessors offer a place to perform memory management or other tasks, which can be controlled to an extent in @synthesized accessors through the use of nonatomic/copy/etc. You can still directly access the instance variable a property masks by using the instance variable’s name instead of self.propertyName. By default, the instance variable’s name is the property’s name preceded by an underscore. The underscore prevents people from accidentally directly accessing the instance variable when they don’t mean to and can prevent namespace collisions. You can also implement your own accessors.

    self.myArray //goes through the setter/getter of the property
    _myArray     //directly accesses backing instance variable while ignoring accessors
    myArray      //incorrect
    

    Note that the name of the backing instance variable can be changed using @synthesize myPropertyName = myCoolName.

    In terms of usage, in most cases you would use self.thing. The exception would be custom setters/getters (ex. return _thing) and dealloc where you would use [_thing release] to counter the retain that was sent to the object when it passed through the retain-style setter. The reason for not calling the accessor within the accessor should be obvious. We don’t use the accessor in dealloc to prevent unwanted effects.

    EDIT: Here’s some nice resources to help you better understand manual reference counting.

    1. Understanding reference counting with Cocoa and Objective-C
    2. Memory Management Programming Guide (from Apple)

    Also, if you want to develop for iOS consider using ARC. ARC stands for Automatic Reference Counting. Unlike MRC (Manual Reference Counting) where you explicitly add retain and release calls to your code, ARC conservatively handles reference counting for you, retaining and releasing objects as it sees fit. You can read about ARC below.

    1. Transitioning to ARC (from Apple)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to understand memory management on iOS. I created this interface: @interface Player
I have a UITabBar that I am trying to style after the new iOS
I'm new to iOS development and I'm trying to understand if is it's possible
I am fairly new to iOS development and trying make a simple app which
I'm trying some iOS test applications on the new Mac mini, that supports Bluetooth
I am new to iOS developement, and i am trying to understand the whole
Somewhat new to ios programming. Trying to use AVQueuePlayer and playing multiple videos in
Currently I'm trying to access the files that are transferred using the new iOS
I am new to ios development and I am trying to use some methods
I'm new to iOS and trying to use RestKit. I'm getting a 'sigabrt' exception

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.