• 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: Subclassing NSControl and inheritance of target, action properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subclassing NSControl and inheritance of target, action properties


  • Subject: Re: Subclassing NSControl and inheritance of target, action properties
  • From: Ken Thomases <email@hidden>
  • Date: Thu, 29 Jan 2015 23:16:29 -0600

On Jan 29, 2015, at 10:54 PM, Quincey Morris <email@hidden> wrote:

> On Jan 29, 2015, at 19:47 , Greg Parker <email@hidden> wrote:
>>
>> `atomic` makes a big difference for a strong or weak property of object type because objects have retain counts.
>
> Er, I feel stupid but I don’t understand. How do the retain counts affect this? On the one hand, properties are not the only place where retain counts are manipulated, and on the other hand, don’t retain count changes have to be atomic anyway?

The getter for a strong property needs to return either nil or a pointer that's valid.  It can't return a pointer to an object that's been deallocated.  If the thread on which the getter has been called is racing a thread which is setting the property to a different pointer (and thus releasing a reference), the getter has to do the equivalent of retain+autorelease atomically with respect to the setter doing a (retain new value)+(replace pointer)+(release old value).

For a weak property, the property has to be registered with the runtime as the location for a particular weak object and, when set to a new value, unregistered.  The runtime needs to know the location of all weak pointers to each object so that when the object is (about to be) deallocated, it can nil out those pointers. Basically, the racing threads are calling objc_loadWeak() vs. objc_storeWeak().  The former has, again, the semantics of a retain+autorelease so that the reference is valid for the caller's context (if it's not nil).

Regards,
Ken


_______________________________________________

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: Subclassing NSControl and inheritance of target, action properties
      • From: Quincey Morris <email@hidden>
References: 
 >Subclassing NSControl and inheritance of target, action properties (From: Graham Cox <email@hidden>)
 >Re: Subclassing NSControl and inheritance of target, action properties (From: Roland King <email@hidden>)
 >Re: Subclassing NSControl and inheritance of target, action properties (From: Graham Cox <email@hidden>)
 >Re: Subclassing NSControl and inheritance of target, action properties (From: Quincey Morris <email@hidden>)
 >Re: Subclassing NSControl and inheritance of target, action properties (From: Roland King <email@hidden>)
 >Re: Subclassing NSControl and inheritance of target, action properties (From: Quincey Morris <email@hidden>)
 >Re: Subclassing NSControl and inheritance of target, action properties (From: Greg Parker <email@hidden>)
 >Re: Subclassing NSControl and inheritance of target, action properties (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Modifying row rect indent in NSOutlineView
  • Next by Date: copyWithZone archive/unarchive
  • Previous by thread: Re: Subclassing NSControl and inheritance of target, action properties
  • Next by thread: Re: Subclassing NSControl and inheritance of target, action properties
  • Index(es):
    • Date
    • Thread