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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:33:06+00:00 2026-05-14T20:33:06+00:00

In my .h file I have: NSMutableArray *myArray; @property (nonatomic, retain) NSMutableArray *myArray; My

  • 0

In my .h file I have:

NSMutableArray *myArray;
@property (nonatomic, retain) NSMutableArray *myArray;

My .m file looks basically like this:

@synthesize myArray;

- (id) init {
    self = [super init];

    if (self != nil)
    {
        self.myArray = .... ? // here I want to create an empty array
    }

    return self;
}

- (void) dealloc {
    [self.myArray release];

    [super dealloc];
}

What I’m not sure about is what do to in the init.

1)

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

2)

NSMutableArray *tmp = [[NSMutableArray alloc] init];
self.myArray = tmp;
[tmp release];

Solution 1 doesn’t seem right to me, because of my @property (retain) setting I automatically increase the retain counter when setting self.myArray, but additionally I have already a “+1 retain” due to the [NSMutableArray alloc] and then ending up with a retain count of 2 for that object, but only releasing once in the dealloc. Thus the second solution seems more correct to me, even though it is cumbersome.

Also am I wondering if self.myArray = ... is actually the same as [self setMyArray:...] and thus does increase the retain count.

UPDATE

I actually found the answers (and even more details) here in case anyone is interested in reading more.

  • 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-14T20:33:06+00:00Added an answer on May 14, 2026 at 8:33 pm

    self.myArray = is exactly the same as [self setMyArray:...].

    You could however do myArray = [[NSMutableArray alloc] init]; which would end up with a retain count of 1 and would be totally legit.

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

Sidebar

Related Questions

I have a static variable on appDelegate declared like this: appdelegate.h file: +(NSMutableArray*)allBanco; +(void)setAllBanco:(NSMutableArray*)value;
I have a NSMutableArray in my app which I initiate like this: H-FILE NSMutableArray
I have .lib file with its header (.h) file. This file have a few
I have file with lines like so: 1 17 A G R:560:500:60:10.71%:1.6329E-19 Pass:1.0:276:0:57:0:1E0 15
I have a haskell file test.hs. In this file I have written a function
I want to trim the file extension from text I have an NSMutableArray in
I have declared an NSMutableArray *categories in my view controller .h file, and declared
Assuming I have an NSMutableArray which is loaded from file: searchTermsArray = [[NSMutableArray alloc]
I have this code: for the simulator to write a NSmutableArray in a plist
In rootViewController.h i have a property NSMutableArray mainList: @interface RootViewController : UITableViewController { NSMutableArray

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.