Re: Proper retain/release etiquette
Re: Proper retain/release etiquette
- Subject: Re: Proper retain/release etiquette
- From: Philip George <email@hidden>
- Date: Tue, 23 Jul 2002 09:55:57 -0500
>
>> 10. It is bad practice to do: id bar = [Foo alloc]; [bar init];
>
>> because
>
>> init might hand back a different object than the original alloc did.
>
>
>
> This is programmatically similar to nesting the two i.e id bar =
>
> [[Foo alloc] init]. So i think it makes no difference.
>
>
Actually, it's _not_ programmatically similar, for exactly the reason
>
the OP mentioned. In "id bar = [[Foo alloc] init];" bar is assigned the
>
result of the init method. In "id bar = [Foo alloc]; [bar init];" bar
>
is assigned the result of an alloc method. The result of the init
>
method - which may not be the receiver - is thrown away.
>
Correct. I just read this exact explanation in official Apple
documentation (wish I could remember which doc).
**Always** use the form:
bar = [[Foo alloc] init];
Never alloc then init in separate statements.
- Philip
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.