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



On Fri, Apr 18, 2008 at 12:58 PM, Optical Ali <email@hidden> wrote:

int main(int argc, char *argv[])

{

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    

NSMutableArray *kArr = [NSMutableArray arrayWithObjects:@"1", @"2", @"3", @"4", nil];

NSMutableArray *aArr = [NSMutableArray arrayWithObjects:@"2", nil];

NSDictionary *aDic = [NSDictionary dictionaryWithObjectsAndKeys:

@"K", kArr, @"A", aArr, nil];


I think you're doing this backwards. It's "ObjectsAndKeys", not "KeysAndObjects".

int n = [kArr retainCount];

// Shouldn't n be 2 here?

        [pool release];

         return 0;

}


The #1 rule is that you cannot infer anything from the retain count. It's is for the system's use, not yours.

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.
 _______________________________________________
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>)



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.