Re: Accessing interface elements (iPhone vs Mac)
Re: Accessing interface elements (iPhone vs Mac)
- Subject: Re: Accessing interface elements (iPhone vs Mac)
- From: Adam Venturella <email@hidden>
- Date: Wed, 21 Jan 2009 10:38:56 -0800
I also just found this bit in the docs:
http://developer.apple.com/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/chapter_3_section_4.html#//apple_ref/doc/uid/10000051i-CH4-SW18
Nib Object Retention
iPhone OS - managed memory model
Objects in the nib file are created with a retain count of 1 and then
autoreleased. As it rebuilds the object hierarchy, however, UIKit
reestablishes connections between the objects using the
setValue:forKey: method, which uses the available setter method or
retains the object by default if no setter method is available. If you
define outlets for nib-file objects, you should also define a setter
method for accessing that outlet. Setter methods for outlets should
retain their values, and setter methods for outlets containing
top-level objects must retain their values to prevent them from being
deallocated. If you do not store the top-level objects in outlets, you
must retain either the array returned by the
loadNibNamed:owner:options: method or the objects inside the array to
prevent those objects from being released prematurely.
So as Dave stated, creating the properties is the recommended way,
though if the properties are not present, then a retain will be sent
to the object anyway. I guess that is a nice fail-safe they put in
place.
On Wed, Jan 21, 2009 at 10:33 AM, Dave DeLong <email@hidden> wrote:
> On Jan 21, 2009, at 11:25 AM, Adam Venturella <email@hidden> wrote:
>
>> I have seen this same behavior too, creating @properties for IBOutlets
>> on the iPhone. I have yet to run into a problem not
>> @property/@synthsizeing my Outlets on the iPhone, everything seems to
>> work just fine if you don't. So am I missing something? And am I
>> correct in assuming you would then be responsible for [myOutlet
>> release] in the dealloc?
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>
> My understanding is that declaring IBOotlets as properties is the
> recommended way of doing things. If you look in template code, you'll see
> that the outlets are released. This is to balance the retains sent during
> nib loading.
>
> So really, it helps clarify the memory management of GUI elements.
>
> Dave
>
> Sent from my iPod._______________________________________________
>
> 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
>
_______________________________________________
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