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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:44:28+00:00 2026-05-15T08:44:28+00:00

I declared a NSMutableArray in the header-file with: NSMutableArray *myMuArr; and @property (nonatomic, retain)

  • 0

I declared a NSMutableArray in the header-file with:

NSMutableArray *myMuArr;

and

@property (nonatomic, retain) NSMutableArray *myMuArr;

In the .m file I’ve got a delegate from an other class:

-(void)didGrabData:(NSArray*)theArray {
self.myMuArr = [[[NSMutableArray alloc] initWithArray:myMuArr]retain];
}

If I want to access the self.myMuArr in cellForRowAtIndexPath it’s empty (I checked the retain count of the array and it’s 0)

What am I doing wrong?

Of course it’s released in the dealloc, no where else.

I would be very thankfull for any help :0)

  • 1 1 Answer
  • 1 View
  • 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-15T08:44:29+00:00Added an answer on May 15, 2026 at 8:44 am

    I don’t think you understand when to retain and release. Take a look at this SO question and answer. Read it thru and understand it and the read the articles it links to. It will help you a lot. It is essential to understand this on the iPhone.

    Your array is getting retained 3 times, but you only needed one:
    (1) When you call alloc/init, you get an array that you own (it is retained).
    (2) When you called retain, that’s an extra retain.
    (3) Your setter self.myMuArr was defined to retain in the @property, so when you assign the pointer using the setter method it gets retained again.

    You commonly see code use these two techniques, both are correct:

    -(void)didGrabData:(NSArray*)theArray {
       NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:obj1, obj2, nil];
       self.myMutArr = arr;
       [arr release];       
    }
    

    Or using arrayWithObjects, which gives you an autoreleased array that you need to retain if you want to take ownership of its memory space and keep it around. Your setter will do that:

    -(void)didGrabData:(NSArray*)theArray {
       self.myMutArr = [NSMutableArray arrayWithObjects:obj1, obj2, nil];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable declared like this: @property (nonatomic, retain) NSMutableArray *aInfo; At the
I have a NSMutableArray property declared as (nonatomic, retain) called Categories. In dealloc, I
I have a property declared like this: @property (nonatomic, retain) NSMutableArray *pricingLevels; And I
I declared a NSArray object in .h file as @property (nonatomic, assign) NSArray *scnArray;
I have a static variable on appDelegate declared like this: appdelegate.h file: +(NSMutableArray*)allBanco; +(void)setAllBanco:(NSMutableArray*)value;
Possible Duplicate: NSMutableArray addObject not working I have a NSMutableArray declared as (nonatomic,retain) in
I declared a delegate: public delegate void Del(string message); Then i created a function
I have declared an NSMutableArray *categories in my view controller .h file, and declared
I declared an NSMutableArray in my .h and I set property and synthesize, but
in my class i have a NSMutableArray declared and used. One of the methods

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.