• 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: Jeff Laing <email@hidden>
  • Date: Tue, 9 Mar 2010 23:58:55 +0000
  • Acceptlanguage: en-US
  • Thread-topic: [[Class alloc] init] preferable over [[Class instance] retain]?

> For example, is:
>
> NSMutableArray *anArray = [[NSMutableArray array] retain];
>
> better than:
>
> NSMutableArray *anArray = [[NSMutableArray alloc] init];

I've been reamed, in the recent past, for expressing the opinion that the first was just as good as the second - apparently the answer depends on what platform you're on.

The upshot was that apparently the iPhone developers like you to avoid the use of autorelease pools where possible.  One hidden difference in the above is that in the first case you have (probably) populated the autorelease pool and in the other you (probably) haven't.

I say probably because you can't know for sure in the majority of cases (its not explicitly documented). And there are aberrant cases like NSDateFormatter whose -init creates a bunch of autoreleased objects that you never see.

(When worrying about memory usage, don't blindly trust documentation or heresay.  Use Instruments!)

Orthogonally, there are classes like NSPredicate where you don't have a choice - there are only convenience methods, no initPredicateWithFormat:

_______________________________________________

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

References: 
 >[[Class alloc] init] preferable over [[Class instance] retain]? (From: Laurent Daudelin <email@hidden>)

  • Prev by Date: Re: Bison/Yacc with Objective-C ?
  • Next by Date: Core Data & Spotlight: Record-Level Indexing : Issues?
  • Previous by thread: Re: [[Class alloc] init] preferable over [[Class instance] retain]?
  • Next by thread: Re: [[Class alloc] init] preferable over [[Class instance] retain]?
  • Index(es):
    • Date
    • Thread