• 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: mmalc Crawford <email@hidden>
  • Date: Tue, 19 Jan 2010 18:01:14 -0800

On Jan 19, 2010, at 5:50 pm, Jeff Laing wrote:

>> Yes, and it autoreleases it too. :-o That means it'll conveniently be
>> released later on, which is exactly what you're running into. If you
>> want to keep a reference to the dictionary, you should call alloc and
>> init yourself.
>
> 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.

If you want to assign the dictionary to an instance variable, you should use an accessor method. In this case, it's still better to use alloc/init then release the dictionary when you've finished with it.

If you want to create the dictionary, use it temporarily, then forget about it, then dictionaryWithCapacity is OK, but again (particularly on iPhone) best practice is still to use alloc/init+release.

mmalc

_______________________________________________

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: NSDictionary trouble
      • From: Jeff Laing <email@hidden>
    • Re: NSDictionary trouble
      • From: Shawn Rutledge <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>)

  • Prev by Date: RE: NSDictionary trouble
  • Next by Date: Help Understanding CFRunLoopSourceSignal and CFRunLoopWakeUp
  • Previous by thread: RE: NSDictionary trouble
  • Next by thread: Re: NSDictionary trouble
  • Index(es):
    • Date
    • Thread