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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:04:14+00:00 2026-06-12T22:04:14+00:00

I am stuck in the middle of memory management stuff. Please help me out

  • 0

I am stuck in the middle of memory management stuff. Please help me out in solving my question.

NSMutableArray *array = [[NSMutableArray alloc]init];
Object *obj = [[Object alloc]init];  
[array addObject: obj];  
[obj release];  

Is it necessary to release obj in above code?

  • 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-12T22:04:15+00:00Added an answer on June 12, 2026 at 10:04 pm

    The answer to your question is: yes, if you don’t use ARC. If you are writing a new app, you should seriously consider using ARC.

    Container objects in Objective-C always balance their retain/release count. In other words, you should always manage memory as if you did not add the object and make sure your own code balances its retain count. Note that this is a convention and is not enforced, but you could always trust the built-in classes to follow this convention. Also, you can perform a static analysis (Cmd+Shift+B in XCode) to detect these problems. It would have pinpointed this in your code above.

    The correct code in the case above would be:

    NSMutableArray *array = [[NSMutableArray alloc]init];
    Object *obj = [[[Object alloc]init]autorelease];
    [array addObject: obj];
    

    or

    NSMutableArray *array = [[NSMutableArray alloc]init];
    Object *obj = [[Object alloc]init];
    [array addObject: obj];
    [obj release];
    

    since NSMutableArray (and its cousins) will retain the object as long as it is in the collection.

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

Sidebar

Related Questions

I'm currently learning about low level arduino stuff including memory. My question is since
Actually I am stuck in middle of some mysql code. Can anyone suggest a
I was stuck in the middle of no such table error while I created
I am stuck in the middle of this problem for a week or so
I've recently got stuck in the middle of choosing between an ivar and static
python n00b here doing the pythonchallenge, stuck on middle of a level right now.
I am just stuck in the middle of the project. My objective is to
I'm reviewing algorithm stuff and stuck in a simple quick sort algorithm implementation in
Hey I am stuck in the middle of my code. I am getting some
I am stuck with solving my assignment. Here is what it states, Consider the

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.