Re: Accessors Question
Re: Accessors Question
- Subject: Re: Accessors Question
- From: Jens Alfke <email@hidden>
- Date: Thu, 12 Jun 2008 11:27:36 -0700
On 12 Jun '08, at 10:41 AM, Andy Lee wrote:
I hadn't thought of this case.
Thanks for the pointer to the docs -- I now see there is a
vulnerability in the accessors I've been writing.
This is kind of a religious issue. Some people like the safer
accessors. Some people see them as a very expensive* workaround for a
problem that rarely occurs.
I'm firmly in the latter camp. I've never used this 'safe' form of
accessor, and have only rarely run into the kind of crash it prevents;
and it was always pretty easy to track down and fix. (The fix is just
for the caller to retain the value it got from the accessor, then
release it when it's done using it.)
Another alternative is to leave the getters simple, but change the
_setter_ methods to autorelease the old value instead of releasing it;
that prevents this same crash, but is less expensive because setters
are much more rarely called than getters (and -autorelease isn't much
more expensive than -release.)
—Jens
* A basic accessor requires one or two machine instructions to do the
actual work; whereas -retain and -autorelease involve extra method
dispatches that each acquire a global lock and do a hashtable lookup.
Obviously any one call isn't going to take a noticeable amount of
time, but accessor calls are so damn ubiquitous that this can have an
overall impact on app performance in some cases. Not to mention memory
usage, since autoreleased objects have a longer lifespan and can build
up during loops.Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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