• 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: [[Class alloc] init] preferable over [[Class instance] retain]?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: [[Class alloc] init] preferable over [[Class instance] retain]?
      • From: Alexander Spohr <email@hidden>
References: 
 >[[Class alloc] init] preferable over [[Class instance] retain]? (From: Laurent Daudelin <email@hidden>)

  • Prev by Date: [[Class alloc] init] preferable over [[Class instance] retain]?
  • Next by Date: Re: [[Class alloc] init] preferable over [[Class instance] retain]?
  • Previous by thread: [[Class alloc] init] preferable over [[Class instance] retain]?
  • Next by thread: Re: [[Class alloc] init] preferable over [[Class instance] retain]?
  • Index(es):
    • Date
    • Thread