Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects)
Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects)
- Subject: Re: Outlets / IBOutlet declarations (was Re: Interface Builder & Wiring Objects)
- From: Brian Stern <email@hidden>
- Date: Tue, 18 Nov 2008 04:05:47 -0500
On Nov 18, 2008, at 2:12 AM, Jonathan Hess wrote:
Which parts do you feel are contrary? I'm guessing it's that outlets
with no setters are retained.
Yes, that's the root of the whole issue. The fact is that outlets
without setters that are retained aren't released by the code that
retained them. The responsibility for releasing them is implicitly
passed on to some other code. I misunderstood this after reading that
paragraph a number of times because it is simply contrary to my
understanding of Cocoa memory management. I think it is contrary to
the Cocoa memory management rules that the code that retains these
objects isn't releasing them.
Now that I know that, there are still problems. The outlets can be
released in more than one place. As mmalc mentioned, the view
controller's view may be unloaded in response to a memory warning.
However, the view won't be unloaded if the view controller is the
frontmost view controller. There's no simple way for a view
controller subclass to know if it's the frontmost view controller or
therefore if its view will be unloaded. There is no viewDidUnload
callback that would be the right place to release the outlets in this
case. The code that mmalc showed is not correct because it doesn't
take into account the fact that the frontmost view controller won't
unload its view.
In effect it is the UIViewController base class that is retaining the
outlets, or causing them to be retained, when the nib is loaded. But
it abdicates responsibility for them. The UIViewController base class
is also the class that is releasing its view without any notification
to the derived class that it should also release the outlets.
I haven't decided how I'm going to fix all this. Either I'll add
assign properties so the outlets are not retained or I'll release them
all in viewDidLoad.
Most nib-loading on iPhone OS is done by UIViewController and I
suppose most of my complaints above are with the UIViewController
implementation. In my code I would hardly ever have a reason to want
to retain an outlet. Having outlets be retained by default gives my
code no benefit, and causes some complications.
--
Brian Stern
email@hidden
_______________________________________________
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