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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:58:13+00:00 2026-05-17T17:58:13+00:00

I am trying to understand a little more about memory management. Knowing that I

  • 0

I am trying to understand a little more about memory management. Knowing that I need to release anything that I have init or alloc’ed I am confused about the following:

- (NSMutableArray *)getData {
    NSMutableArray *data = [[NSMutableArray alloc] init];
    NSString *first = @"First object";
    [data addObject:first];
    NSString *second = @"Second object";
    [data addObject:second];

    return data;

}

Since I used alloc and init, I know I need to release my data object. But if I add autorelease to the init part or to the return, it crashes when I run the method.

What is the correct way to do something like this with correct memory management for iPhone?

  • 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-17T17:58:14+00:00Added an answer on May 17, 2026 at 5:58 pm

    You should autorelease, like you said. The caller probably needs to retain, like this – especially if storing into an instance variable:

    NSMutableArray *array = [[obj getData] retain];
    

    Later, when it’s totally done with it:

    [array release]; // balances the retain above
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to understand a little more about Crockford's approach to Prototypical Inheritance whereby he
I am trying to understand a little bit more about Matlab classes and their
I'm trying to understand ReST and XML a little more - A third party
I'm looking to understand a bit more about LINQ and use it a little
I am trying to understand JavaScript a little better and am having trouble creating
been fooling around with YQL trying to understand it a little better. I've managed
I am trying to understand Http/Https a little better and possibly what headers I'm
I'm going a little nuts trying to understand the doc on impersonation and delegation
I am trying understand ViewModels deeper and I have read many articles and blogs
So I am trying to understand OOP more and use it. The following code

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.