Re: NSString property: copy or retain?
Re: NSString property: copy or retain?
- Subject: Re: NSString property: copy or retain?
- From: Ricky Sharp <email@hidden>
- Date: Mon, 22 Dec 2008 16:41:01 -0600
On Dec 22, 2008, at 4:04 PM, Debajit Adhikary wrote:
Let's say I have a class called SomeClass with a string property name:
@interface SomeClass : NSObject{
NSString* name;
}
@property (nonatomic, retain) NSString* name;
@end
I understand that name may be assigned a NSMutableString in which
case this
will may to errant behavior.
(1) For strings in general, is it *always* a good idea to use the
"copy"
attribute instead of "retain"?
No. This isn't a "one way or another" situation. It's really up to
what you need. Having said that, there are good guidelines as to why
you'd want to use one over the other. Look at the memory-management
guidelines or search the archives.
(2) Is a "copied" attribute in any way less efficient than such a
"retain-ed" attribute?
Definitely. It will cost more cycles to copy the object vs. retain
it. And, will use more memory. However, the performance and memory
costs may not have any noticeable impact on your code. A profiler can
tell you for sure.
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
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