On Nov 19, 2008, at 7:00 AM, Brian Stern wrote:

This leaves us for now with two solutions:
(a) Greg's (override setView:) which is more future-proof but is in many respects academically unsatisfying. (b) For non-top-level-object, specify an assign attribute for the property -- and risk dangling pointers.

The override of setView is very similar to the viewDidUnload callback that I proposed as a solution for this. It has its own further issues. UIViewController calls [setView:nil] from its dealloc method so the subclass has to be prepared for this. What I've done is to add all the public retain properties for all the outlets. Additionally I've added a

-(void)releaseOutlets

method that uses the properties and sets them all to nil. I call this method from my subclass's dealloc method and setView: override. That way I only have one place to write the code that releases all the outlets.


Brian,

What is your reason for having a separate -releaseOutlets method to do this?

The sample that I gave (calling self.anOutlet = nil; when the argument to -setView: is nil) will do whatever releasing is required (if the anOutlet property is "retain") or simple zeroing the pointer (if the anOutlet property is "assign"). The fact that UIViewController calls - setView:nil from its -dealloc is just additional convenience. All of your outlets get cleaned up at the same time as the UIViewController cleans up the main view. There is no need to write any outlet related code in your -dealloc at all, since it is all handled via the superclass and the -setView: override.

In short, the way I think of it, -setView: _IS_ the one centralized place that deals with all view-related pointers, including all outlets. And UIViewController calls -setView: at all the necessary times (setup, memory warning, dealloc), so you don't have to do anything else.

Hope this helps,
        - Greg
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to