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: Alexander Spohr <email@hidden>
- Date: Tue, 9 Mar 2010 22:50:10 +0100
Am 09.03.2010 um 22:44 schrieb Luke the Hiesterman:
>
> 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.
I’d use
NSMutableArray *anArray = [NSMutableArray new];
in this case ;)
atze
_______________________________________________
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