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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:34:47+00:00 2026-05-17T22:34:47+00:00

I am worried about than am I properly adding object and releasing them. What

  • 0

I am worried about than am I properly adding object and releasing them.

  1. What NSMutableArray actually contain – object’s copy or just a pointer to them?
  2. What is the sequence in working with NSMutableArray? (alloc, init, work, release)
  3. How to retain and release it properly?

    NSMutableArray *listData = [[NSMutableArray alloc] init];
    int i = 0;
    for (i = 0; i < 3; i++)
    {
        MyData *obj = [[MyData alloc] init];
        NSString *name = nil;
        switch (i)
        {
            case 0:
                name = @"Semen";
                break;
            case 1:
                name = @"Ivan";
                break;              
            case 2:
                name = @"Stepan";
                break;              
            default:
                break;
        }       
        obj.name = name;
        [listData addObject: obj];
        [obj release];
     }
     [listData release]  //in dealloc method
    

or I need to release all contained objects first and only than do release on NSMutableArray object?

Thanks!

  • 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-17T22:34:47+00:00Added an answer on May 17, 2026 at 10:34 pm

    NSMutable array contains the reference to the object. When you add an object to NSMutableArray, it will retain the object. That is, after adding the object to the array you should release it. When you are done with that object in array, you can remove the object from the array. Upon removing, the object automatically receives a release message. So you don’t need to send it another release message. And if you release the array itself, no need to send release message to all objects, as during the deallocation of NSMutableArray it will send release to all objects that it contains.

    1. alloc NSMutableArray.
    2. alloc object1.
    3. add object1 to array.
    4. release object1.
    5. alloc object2.
    6. add object2 to array.
    7. release object2.
    8. add as many objects as needed in this manner.
    8. work with object1.
    9. remove object1 from array. it will receive a release automatically.
    10. release the array. object2 and others will receive a release.
    

    Hope it helps.

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

Sidebar

Related Questions

During our initial development we haven't worried about scaling concerns, just getting the bare
I was worried about C#'s speed when it deals with heavy calculations, when you
I am worried about the reliability of the MinGW compiler for 64-bit, as an
To what degree should I be worried about the following warning that is displayed
I'm working on a webservice + AJAX interface, and I'm worried about authentication. This
I have finally got in my mind what worried me about Dependency Injection and
I'm wondering that how much worried I should be about data types. I can
In another question I was worried about using a web service that takes a
Currently I have a pure silverlight website with navigation. Im worried about the customers
I have an ASP.NET application with a shopping-cart type of scenario. I'm worried about

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.