• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: memory mgmt for NSMutableArray as ivar
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: memory mgmt for NSMutableArray as ivar


  • Subject: Re: memory mgmt for NSMutableArray as ivar
  • From: Daniel Child <email@hidden>
  • Date: Wed, 22 Aug 2007 23:34:20 -0400

Thanks for the clarification! I put in your suggestions and it works fine.

I am actually creating a singleton class, and so I simply want an empty array to exist upon getting the singleton instance.

If I use your first approach:
- (id)initWithArray:(NSMutableArray *)anArray {
	if (self = [super init]) {
		[self setList:anArray];
	}
	return self;
}
then what about the management in the calling portion.

MySingleton *ms = [MySingleton getInstance];

On Aug 22, 2007, at 12:42 AM, Andrew Merenbach wrote:

- (id)initWithArray:(NSMutableArray *)anArray {
	if (self = [super init]) {
		[self setList:anArray];
	}
	return self;
}

Or:

- (id)init {
if (self = [super init]) {
NSArray *array = [NSArray arrayWithObjects:@"hello", @"mary", @"lou", nil];
[self setList: array];
}
return self;
}


In some cases, you may just wish to alloc the array yoruself--for instance, although the -init code above is very clear, you may wish to do:

- (id)init {
if (self = [super init]) {
list = [[NSArray alloc] initWithObjects:@"hello", @"mary", @"lou", nil];
}
return self;
}

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: memory mgmt for NSMutableArray as ivar
      • From: mmalc crawford <email@hidden>
References: 
 >memory mgmt for NSMutableArray as ivar (From: Daniel Child <email@hidden>)
 >Re: memory mgmt for NSMutableArray as ivar (From: Andrew Merenbach <email@hidden>)

  • Prev by Date: Re: RS: declaration bug
  • Next by Date: Re: How to get selection of submenu
  • Previous by thread: Re: memory mgmt for NSMutableArray as ivar
  • Next by thread: Re: memory mgmt for NSMutableArray as ivar
  • Index(es):
    • Date
    • Thread