discuss-gnustep
[Top][All Lists]
Advanced

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

Re: Setter Gettor method style


From: Martin Häcker
Subject: Re: Setter Gettor method style
Date: Sat, 3 Aug 2002 14:18:00 +0200

 >   - (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.

         title = [newTitle copy];
         // or retain, depending on object & usage
 >   }

:) I certainly don't want to question your wizardry, but as far as I understand this this style was chosen because of something like this:

        ...
        NSString *str = [myDocument title];
        ...
        [myDocument setTitle:@"cool"];
        ...
        NSLog(@"I've got a %@", str);

And the string should remain valid for the rest of the routine. (Perhaps this also has something to do with OS X having no Garbage Collection)

Peace,
Martin
--
dont.wanna.tell
[ot]coder - hehe



reply via email to

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