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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:36:29+00:00 2026-05-11T01:36:29+00:00

NSMutableArray *a1 = [[NSMutableArray alloc] init]; NSMutableArray *a2 = [NSMutableArray array]; TempObj *obj =

  • 0
NSMutableArray *a1 = [[NSMutableArray alloc] init]; NSMutableArray *a2 = [NSMutableArray array];  TempObj *obj = [[TempObj alloc] init]; //assume this line is repeated for each obj [a1 addObject:obj]; [a1 addObject:obj2]; [a1 addObject:obj3]; [a1 addObject:obj4];  [obj release]; [obj2 release]; [obj3 release]; [obj4 release];  [a1 release]; 

Ok so a2 is an autorelease obj so I don’t have to call release on it? Also how do you know when you get an autorelease object?

And for a1, I don’t have to loop through the array and release each object first? What if I called [a1 removeAllObjects]; does that call [[a1 objectAtIndex:#] release];

Am I supposed to release those objects after I’ve added them to the array?

  • 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. 2026-05-11T01:36:30+00:00Added an answer on May 11, 2026 at 1:36 am

    When you add an object to an array, it calls retain on that object. If you don’t release your pointer to that object, it will be a leak. When you release the array, it will call release on all of the objects that it holds, since it called retain previously.

    As for autorelease vs release, the only way to know for sure (aside from possibly reading the documentation) is by the name of the method. I believe the rule in general is that if you didn’t allocate the object, then you aren’t responsible for releasing it.

    Regarding the object creation methods, all of the convenience methods (array:, arrayWithObjects:, arrayWithArray:, etc.) return autoreleased objects. However, their corresponding init methods (init:, initWithObjects:, initWithArray:, etc.) do not – if you call them, you are responsible for calling release on the returned object.

    I seem to recall a few other questions on this topic here – you might try searching around for a more thorough explanation.

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

Sidebar

Ask A Question

Stats

  • Questions 60k
  • Answers 60k
  • 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
  • added an answer It is not supported natively by jQuery, but you can… May 11, 2026 at 9:29 am
  • added an answer I've not done C++ for a long time but from… May 11, 2026 at 9:29 am
  • added an answer You might consider writing three separate stored procedures but then… May 11, 2026 at 9:29 am

Related Questions

NSMutableArray *a1 = [[NSMutableArray alloc] init]; NSMutableArray *a2 = [NSMutableArray array]; TempObj *obj =
I have a class that subclasses NSMutableArray. I init it using: MyClass class =
When retrieving objects from an NSMutableArray in cocoa-touch is the below code ok? Should
For a simple example of using a NSMutableArray of strings called rows, what do
A class has a property (and instance var) of type NSMutableArray with synthesized accessors
Newbie question. I have a NSMutableArray that holds multiple objects (objects that stores Bezier
I am trying to get key-value-observing to work for an NSMutableArray. Below is the

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.