Possible Duplicate:
NSString @property, using copy instead of retain
I have a basic memory management problem as below:
NSString *someName = [NSString stringWithFormat:@"Chris"];
Person *p = [[Person alloc] init];
p.name = someName;
if “name” is set to be “retain”, I know that “someName” will be autorelease once and retain once, so “p.name” will keep the NSString with one retainCount.
But how about if “name” is set to be copy. Although “someName” give a copy of itself to “p.name”, but the copy one is stil will be autorelease, right? So, do I need to retain “someName” explicitly?
No, copy does not autoreleased the copy before it returns it (or, to put it another way, it returns an object that you own). Copy properties would be pretty worthless if it did, wouldn’t they?