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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:48:59+00:00 2026-05-27T12:48:59+00:00

@interface foo: NSObject @property (nonatomic, retain) NSMutableArray *aMutableArray; @end @implementation @synthesize aMutableArray -(void)somefunction {

  • 0
@interface foo: NSObject
@property (nonatomic, retain) NSMutableArray *aMutableArray;
@end

@implementation
@synthesize aMutableArray

-(void)somefunction {
    // Illustration
    self.aMutableArray = [[[NSMutableArray alloc]init]autorelease];
    self.aMutableArray = [[[NSMutableArray alloc]init]autorelease];
    self.aMutableArray = [[[NSMutableArray alloc]init]autorelease];
}
@end

I have done code similar code to this in other parts of my program, but I needed to be certain that this does not cause a memory leak. With my understanding of autorelease, this object is released correctly right?

[EDIT – added question]
One question though: the property above has a retain attribute, so when the compiler creates the setter function, the setter code will look something like this:

somecode..
retain newObj
release oldObj
somecode..

in the code above, I assigned 3 objects to aMutableArray.
Each time they are assigned, the setter function did a retain on the newObj and a release on the oldObj. So, since the setter method already did a release, will there be a problem when the autorelease kicks-in to release the object a second time?

  • 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-27T12:48:59+00:00Added an answer on May 27, 2026 at 12:48 pm

    Yes, it will be released correctly if you also release it dealloc method:

    - (void) dealloc{
       [aMutableArray release];
       [super dealloc];
    }
    

    Note also that you can shorten your code using equivalent convenience +array method of NSMutableArray:

    self.aMutableArray = [NSMutableArray array];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a class @interface Foo { NSString *temp; } @property(nonatomic, copy) NSString
I have created a class named Foo : @interface Foo:NSObject{ int myInt; } @property
@protocol protoA <NSObject> @end @interface objA : NSObject<protoA> { @private } @end @implementation objA
Assume that I have this piece of code: @interface Foo : NSObject { Bar
Given the following interfaces: interface IFoo { void Foo(); } interface IBar : IFoo
For example public interface X{ public void foo(X i); } public class Y implements
I have seen a lot of code like this header.h @interface Foo : NSObject
Suppose I have this code... foo.h @interface Foo : NSObject { NSString *aString; //
lets say I have aclass @interface Foo :NSobject { NSstring *a; NSDate *b; }
I have a NSArray of Foo objects. @interface Foo : NSObject { } -

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.