Re: memory mgmt for NSMutableArray as ivar
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