• 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: NSString property: copy or retain?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSString property: copy or retain?
      • From: "Clark Cox" <email@hidden>
References: 
 >NSString property: copy or retain? (From: "Debajit Adhikary" <email@hidden>)

  • Prev by Date: Re: NSString property: copy or retain?
  • Next by Date: Re: NSString property: copy or retain?
  • Previous by thread: Re: NSString property: copy or retain?
  • Next by thread: Re: NSString property: copy or retain?
  • Index(es):
    • Date
    • Thread