Re: [[Class alloc] init] preferable over [[Class instance] retain]?
Re: [[Class alloc] init] preferable over [[Class instance] retain]?
- Subject: Re: [[Class alloc] init] preferable over [[Class instance] retain]?
- From: Luke the Hiesterman <email@hidden>
- Date: Tue, 9 Mar 2010 13:44:43 -0800
On Mar 9, 2010, at 1:41 PM, Laurent Daudelin wrote:
> I've been running in that situation and I'm just wondering if there are any advice for/against one or the other method.
>
> For example, is:
>
> NSMutableArray *anArray = [[NSMutableArray array] retain];
There is no reason to use this when you mean
>
> NSMutableArray *anArray = [[NSMutableArray alloc] init];
Both examples yield an NSMutableArray object with a retain count of 1. The first example invokes an autorelease which is canceled out by a retain. The first example could be rewritten as [[[[NSMutableArray alloc] init] autorelease] retain]; When you compare that to the second example, it's easy to see why there's no reason to use the first.
Luke_______________________________________________
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