On Nov 17, 2008, at 7:12 PM, Brian Stern wrote:

On Nov 17, 2008, at 9:11 PM, mmalcolm crawford wrote:

One other consideration, particularly in iPhone applications, is where you might have outlets to subviews of a main view that might be released in sime situations -- e.g. a UIViewController whose view is released in didReceiveMemoryWarning. To ensure that you don't prolong the lifetime of objects you got from the nib, you should set (use your accessor methods to) set those variables to nil in the relevant method, e.g.:

@interface MyController : UIViewController {
UILabel *label;
...
}
@property (nonatomic, retain) IBOutlet UILabel *label;

then

- (void)didReceiveMemoryWarning {
  self.label = nil;
  [super didReceiveMemoryWarning];
}

OK, this issue has come up for me very recently. It appears that on iPhoneOS IBOutlets are retained, regardless of the presence of properties.

No, on iPhone outlets are consistently *not* retained -- which is precisely why you do need to retain top-level objects on iPhone. But absent accessor methods, connections are made using KVC...
This is documented here:
<http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/chapter_3_section_4.html#//apple_ref/doc/uid/10000051i-CH4-SW6 >


Even worse, in the presence of an assign property the outlet is still retained. Whatever code is retaining the outlets never releases them. So it seems that client code must release all outlets.

As I stated originally, following the pattern I describe above makes memory management consistent in all situations.


The documentation on this is vague, with a lot of 'should's and not clear statements of what really happens.


The documentation at <http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/chapter_3_section_4.html#//apple_ref/doc/uid/10000051i-CH4-SW6 > is explicit, there are just many different situations to consider if you don't follow the property pattern.

mmalc





Actually this isn't (only) related to didReceiveMemoryWarning (which I hadn't considered related to this problem until you raised it).

_______________________________________________

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