Re: NSArray- help!
Re: NSArray- help!
- Subject: Re: NSArray- help!
- From: j o a r <email@hidden>
- Date: Sat, 2 Nov 2002 17:50:17 +0100
You are using a convenience method to construct the array, the
"arrayWithObjects:" method. This method returns an autoreleased array,
meaning that it will be deallocated automatically if you don't
explicitly retain it.
On Saturday, Nov 2, 2002, at 17:37 Europe/Stockholm, Dave Sopchak wrote:
-(id) init
{
GuideStar* guideStar1 = [[GuideStar alloc] init];
GuideStar* guideStar2 = [[GuideStar alloc] init];
GuideStar* guideStar3 = [[GuideStar alloc] init];
GuideStar* test;
if (self = [super init])
{
guideStarArray = [NSArray arrayWithObjects: guideStar1,
guideStar2, guideStar3, nil];
[guideStar1 release];
[guideStar2 release];
[guideStar3 release];
}
}
This should work better:
- (id) init
{
self = [super init];
if (self != nil)
{
GuideStar* guideStar1 = [[GuideStar alloc] init];
GuideStar* guideStar2 = [[GuideStar alloc] init];
GuideStar* guideStar3 = [[GuideStar alloc] init];
guideStarArray = [[NSArray alloc] initWithObjects: guideStar1,
guideStar2, guideStar3, nil];
[guideStar1 release];
[guideStar2 release];
[guideStar3 release];
}
return self;
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.