• 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: NSDictionary trouble
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDictionary trouble


  • Subject: Re: NSDictionary trouble
  • From: Ken Thomases <email@hidden>
  • Date: Tue, 19 Jan 2010 21:38:24 -0600

On Jan 19, 2010, at 9:21 PM, Shawn Rutledge wrote:

> On Tue, Jan 19, 2010 at 7:01 PM, mmalc Crawford <email@hidden> wrote:
>>> No, you should just *retain* the result of dictionaryWithCapacity.
>>>
>> No, you shouldn't.
>>
>> If you're writing an init method and want to assign the dictionary to an instance variable, you should use alloc/init.
>
> Why?

The autorelease pool is convenient and in some cases necessary, but it does come at some cost.  It has some overhead in terms of time and memory, plus it tends to increase the peak memory usage of your program.  (Over time, assuming you've got all your memory management correct, a program's memory usage will come out the same, but autoreleased objects accumulate over the lifetime of the current pool, causing spiky memory usage.)

In general, it's always good to be aware of such trade-offs and make judgments with them in mind.  In a highly constrained environment like the iPhone, the recommendation is to avoid the autorelease pool in the simple cases where it's easy to do so.  Like, the difference between the following:

	someIvar = [[NSMutableDictionary dictionaryWithCapacity:5] retain];

and

	someIvar = [[NSMutableDictionary alloc] initWithCapacity:5];

is not hard on the developer, but keeps usage of the autorelease pool to a minimum.

Regards,
Ken

_______________________________________________

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: 
 >NSDictionary trouble (From: Shawn Rutledge <email@hidden>)
 >Re: NSDictionary trouble (From: Jens Alfke <email@hidden>)
 >Re: NSDictionary trouble (From: Shawn Rutledge <email@hidden>)
 >Re: NSDictionary trouble (From: Graham Cox <email@hidden>)
 >Re: NSDictionary trouble (From: Shawn Rutledge <email@hidden>)
 >Re: NSDictionary trouble (From: Jens Alfke <email@hidden>)
 >RE: NSDictionary trouble (From: Jeff Laing <email@hidden>)
 >Re: NSDictionary trouble (From: mmalc Crawford <email@hidden>)
 >Re: NSDictionary trouble (From: Shawn Rutledge <email@hidden>)

  • Prev by Date: Re: NSDictionary trouble
  • Next by Date: Re: MKPinAnnotationView callout behind other pins
  • Previous by thread: Re: NSDictionary trouble
  • Next by thread: RE: NSDictionary trouble
  • Index(es):
    • Date
    • Thread