Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDictionary and retaining values



Thanks guys! All of your answers are just super.

On Fri, Apr 18, 2008 at 1:45 PM, j o a r <email@hidden> wrote:

On Apr 18, 2008, at 11:04 AM, Mike Manzano wrote:

It should be 1 since you didn't alloc or manually retain kArr. -arrayWithObjects autoreleases the created array. This is true across the Cocoa framework: helper object creation methods always autorelease unless otherwise annotated in the docs.



On Apr 18, 2008, at 11:06 AM, stephen joseph butler wrote:

In this case, kArr is a key in the dictionary, so NSDictionary makes a copy (because keys must be immutable). So the retain count doesn't change.


In the general case, the retain count of an object could change in response to it being copied. A common optimization for immutable classes is to implement "-copy" as a call to "[self retain]". This is obviously a private implementation detail.

In this particular case though, the objects passed as keys are mutable, and they will for that reason not end up in the dictionary at all (Just as Stephen notes above, immutable copies will take their place). This is why you will find that their retain count stays at whatever it was before that call.


j o a r



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/objc-language/email@hidden

This email sent to email@hidden

References: 
 >NSDictionary and retaining values (From: "Optical Ali" <email@hidden>)
 >Re: NSDictionary and retaining values (From: Mike Manzano <email@hidden>)
 >Re: NSDictionary and retaining values (From: j o a r <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.