[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setter Gettor method style

From: Christian Edward Gruber
Subject: Re: Setter Gettor method style
Date: Wed, 14 Aug 2002 07:15:48 -0400

----- Original Message -----
From: "Pascal Bourguignon" <address@hidden>
> >
> >   - (void) setTitle: (NSString *)newTitle {
> > [title autorelease];
> Here, there  is not  advantage to wait  before releasing  title.  It's
> owned by the object, it can  be released directly. If anybody has been
> interested in title it will have  retained it long ago. Since title is
> overwritten immediately, it cannot  be retrieved after this statement,
> so you can as well use release.

Unfortunately untrue.  It is possible, and in a highly multi-processing box,
it is quite feasible that one thread will release the object, which will
release its title, before the calling object's can finish using title.  Even
if someone goes:

id blah = [[[foo title] retain] autorelease]; there's a race-condition setup
there.  It's not likely to fail, but it may fail.  If your code is
multithreaded, then option number 2 is preferable.

> >
> >   - (NSString *) title {
> > return [[title retain] autorelease];
> This is strictly equivalent to { return title; }

No, this is not true if you are in a truly multithreading environment.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]