• 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: Memory Management and @synthesized accessors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory Management and @synthesized accessors


  • Subject: Re: Memory Management and @synthesized accessors
  • From: Stuart Malin <email@hidden>
  • Date: Sat, 21 Feb 2009 09:55:21 -1000




On Feb 21, 2009, at 9:41 AM, Stuart Malin wrote:
So, I am curious as to why the default (retain) behavior of @synthesize does just this?

What makes you think it does? There is no concrete promise about how synthesized accessors are implemented, except that they conform to the declared property attributes (retain vs. copy vs. assign, etc.).

From "The Objective-C Programming Language" pdf (dated 2009-02-04) page 59:


Setter Semantics
These attributes specify the semantics of a set accessor. They are mutually exclusive.
assign
Specifies that the setter uses simple assignment. This is the default.
retain
Specifies that retain should be invoked on the object upon assignment. ( The default is assign.)
The previous value is sent a release message.


Note the last sentence from the above.

But as mmalc pointed out, the behavior is a function of atomicity. Further from the quoted document (page 60):

If you do not specify nonatomic, then in a reference counted environment a synthesized get accessor for
an object property uses a lock and retains and autoreleases the returned value — the implementation will be
similar to the following:
[_internal lock]; // lock using an object-level lock
id result = [[value retain] autorelease];
[_internal unlock];
return result;


Because by default accessors are atomic, this seems to me to be somewhat contrary to the earlier quote.

Ah, sorry to have said this. Further reading of the (updated) docs now make it clear to me that these are harmonious.


You should trust that Apple is synthesizing just about the most appropriate setter imaginable, given the declared property attributes. Unless you need to do something else within the setter -- that is, the setter has additional side effects -- just use @synthesize.

Yes, Ken, I should :-)


_______________________________________________

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: 
 >Memory Management and @synthesized accessors (From: Stuart Malin <email@hidden>)
 >Re: Memory Management and @synthesized accessors (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Memory Management and @synthesized accessors
  • Next by Date: Re: Window Animation with setFrame:display:animate: Flickers
  • Previous by thread: Re: Memory Management and @synthesized accessors
  • Next by thread: Re: Memory Management and @synthesized accessors
  • Index(es):
    • Date
    • Thread