• 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: newbie: question: i have a memory leak: obj-c 2.0: modification of program in "Cocoa with Objective-C"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: newbie: question: i have a memory leak: obj-c 2.0: modification of program in "Cocoa with Objective-C"


  • Subject: Re: newbie: question: i have a memory leak: obj-c 2.0: modification of program in "Cocoa with Objective-C"
  • From: Quincey Morris <email@hidden>
  • Date: Sun, 3 Feb 2008 14:37:33 -0800


On Feb 3, 2008, at 12:45, George Greene wrote:

also, why was it necessary to use
@property(copy, readwrite) NSString *name;
@property(copy, readwrite) NSString *artist;
instead of
@property(readwrite) NSString *name;
@property(readwrite) NSString *artist;

It isn't actually necessary. All you need to do to make the compiler warning go away is write:


@property(assign, readwrite) NSString *name;
@property(assign, readwrite) NSString *artist;

which is what the "(readwrite)" version means anyway.

What's at stake here is whether, if you pass a *mutable* string to setName or setArtist, it should keep a reference to the mutable string object in the instance variable, or whether it should keep a private copy of the string contents at that moment. Depending on the needs of your app, one or other might be the correct answer. The compiler is trying to warn you that the default of "assign" might not be what you wanted.

The problem is that the object's conformance to NSCopying is a lousy way to arbitrate the possible ambiguity. It's really got nothing to do with NSCopying at all. And the poor wording of the warning message isn't a help either.

I submitted a compiler bug for this a week or two ago, so we'll see if the compiler group listens to reason. ;)

P.S. In your case, "(copy, readwrite)" looks like the proper choice, but that's just a guess.
_______________________________________________


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


References: 
 >newbie: question: i have a memory leak: obj-c 2.0: modification of program in "Cocoa with Objective-C" (From: George Greene <email@hidden>)

  • Prev by Date: Re: newbie: question: i have a memory leak: obj-c 2.0: modification of program in "Cocoa with Objective-C"
  • Next by Date: Re: receiving a file on app startup
  • Previous by thread: Re: newbie: question: i have a memory leak: obj-c 2.0: modification of program in "Cocoa with Objective-C"
  • Next by thread: NSOutlineView: How does Cocoa determine a click in a cell can start a drag operation?
  • Index(es):
    • Date
    • Thread