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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:34:13+00:00 2026-05-25T19:34:13+00:00

I know that the basic rule of memory management in objective-C is that for

  • 0

I know that the basic rule of memory management in objective-C is that for every object you do an alloc, you need to release it somewhere.

Say I have the following:

@interface NewPollViewController : UIViewController 
{
   NSMutableArray * myArray;
}

@property (nonatomic, retain) NSMutableArray * myArray;

@implementation NewPollViewController
@synthesize myArray = _myArray;

- (void) viewDidLoad
{
  [super viewDidLoad];
  self.myArray = [[NSMutableArray alloc] init];
}

Say that this self.myArray is used as a dataSource of a UITableView, so when and where should I release this? In the dealloc? I guess that the release in the dealloc corresponds to the retain that I’ve set in my property, so where do I release

  • 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-25T19:34:14+00:00Added an answer on May 25, 2026 at 7:34 pm

    In your example you technically need to release it twice – once in dealloc, and once immediately after setting the property:

    NSMutableArray *a = [[NSMutableArray alloc] init];
    self.myArray = a;
    [a release];
    

    The reasoning for this is because you are specifically allocating memory in viewDidLoad, and then also increasing the retain count when setting the property.

    A way to avoid this is to use one of the static NSMutableArray constructors or use autorelease i.e.

    self.myArray = [[[NSMutableArray alloc] init] autorelease];
    

    Alternatively, bypass the property altogether:

    myArray = [[NSMutableArray alloc] init];
    

    This would avoid the extra retain generated by the property (in fact you could get rid of the property statement if it was only used locally).

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

Sidebar

Related Questions

I have some basic questions around understanding fundamentals of Performance testing. I know that
I know the basic principles about memory management (retain count, autorelease pools etc) in
How do you use money in visual basic I know that I have to
What libraries/methods do you know of that can do some basic HTML representation in
Does anybody know a basic plugin/gem that will allow me to quickly set up
I've been teaching myself python and cgi scripting, and I know that your basic
I know that this is really basic, but I looked everywhere and I cant
So I know that the basic Hello World Program (as in the one to
I know that variations on this question have been asked, but I've tried all
I KNOW that this is basic. But I'm so JS-retarded I can't do-it-myself and

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.