FROM : Ricky Sharp
DATE : Tue Aug 29 17:18:43 2006
On Tuesday, August 29, 2006, at 09:53AM, Andrew Merenbach <andrew.<email_removed>> wrote:
>Hi, all. I've seen threads where this has been beaten to death, but
>I am still left with major questions. I have seen several kinds of
>accessor/mutator methods:
>
>- (void)setFoo:(AMFoo *)aFoo {
> [aFoo retain];
> [myFoo release];
> myFoo = aFoo;
>}
>
>- (void)setFoo:(AMFoo *)aFoo {
> if (aFoo != myFoo) {
> [myFoo release];
> myFoo = [aFoo retain];
> }
>}
>
>- (void)setFoo:(AMFoo *)aFoo {
> id oldFoo = myFoo;
> myFoo = [aFoo retain];
> [oldFoo release];
>}
>
>- (void)setFoo:(AMFoo *)aFoo {
> [myFoo autorelease];
> myFoo = [aFoo retain];
>}
>
>My question is not precisely which is "better," as my understanding
>is that they *all* (or at least the first two and the last one) have
>their merits, speed considerations, etc.
>
>What I want to know, as an intermediate Cocoa programmer--and what I
>have been unable (at least with my own searching) to find on the
>archives--is what are the *advantage* and *disadvantages* of each? I
>know some basics, such as that the last one can apparently make
>debugging in a crash situation rather difficult due to the -
>autorelease call.
>
>But what about number three, for instance? Is it better than number
>two? Does Apple really recommend number one? Why?
See <http://homepage.mac.com/mmalc/Stepwise/accessorMethods2.html>
--
Rick Sharp
Instant Interactive(tm)
DATE : Tue Aug 29 17:18:43 2006
On Tuesday, August 29, 2006, at 09:53AM, Andrew Merenbach <andrew.<email_removed>> wrote:
>Hi, all. I've seen threads where this has been beaten to death, but
>I am still left with major questions. I have seen several kinds of
>accessor/mutator methods:
>
>- (void)setFoo:(AMFoo *)aFoo {
> [aFoo retain];
> [myFoo release];
> myFoo = aFoo;
>}
>
>- (void)setFoo:(AMFoo *)aFoo {
> if (aFoo != myFoo) {
> [myFoo release];
> myFoo = [aFoo retain];
> }
>}
>
>- (void)setFoo:(AMFoo *)aFoo {
> id oldFoo = myFoo;
> myFoo = [aFoo retain];
> [oldFoo release];
>}
>
>- (void)setFoo:(AMFoo *)aFoo {
> [myFoo autorelease];
> myFoo = [aFoo retain];
>}
>
>My question is not precisely which is "better," as my understanding
>is that they *all* (or at least the first two and the last one) have
>their merits, speed considerations, etc.
>
>What I want to know, as an intermediate Cocoa programmer--and what I
>have been unable (at least with my own searching) to find on the
>archives--is what are the *advantage* and *disadvantages* of each? I
>know some basics, such as that the last one can apparently make
>debugging in a crash situation rather difficult due to the -
>autorelease call.
>
>But what about number three, for instance? Is it better than number
>two? Does Apple really recommend number one? Why?
See <http://homepage.mac.com/mmalc/Stepwise/accessorMethods2.html>
--
Rick Sharp
Instant Interactive(tm)
| Related mails | Author | Date |
|---|---|---|
| Andrew Merenbach | Aug 29, 16:53 | |
| Shawn Erickson | Aug 29, 17:15 | |
| Ricky Sharp | Aug 29, 17:18 | |
| Alberto Ricart | Aug 29, 17:51 | |
| Andrew Merenbach | Aug 29, 17:57 | |
| Shawn Erickson | Aug 29, 18:08 | |
| Sean Murphy | Aug 29, 18:10 |






Cocoa mail archive

