Re: overt and covert retain-release question (instigated by UIViewController on iPhone)
Re: overt and covert retain-release question (instigated by UIViewController on iPhone)
- Subject: Re: overt and covert retain-release question (instigated by UIViewController on iPhone)
- From: mmalcolm crawford <email@hidden>
- Date: Wed, 12 Nov 2008 10:36:14 -0800
On Nov 12, 2008, at 10:00 AM, Stuart Malin wrote:
- (void) loadVew
{
contentView = [[UIImageView alloc] initWithFrame........];
...
self.view = contentView;
[contentView release];
...
}
*If* this is exactly the code shown, and contentView is an instance
variable, then this is a poor example. Particularly if contentView is
declared as a retained property:
@property (nonatomic, retain) UIImageView *contentView;
in which case the dealloc method should also release contentView and
you'll then crash when dealloc is invoked.
If contentView is declared as an assigned property:
@property (nonatomic, assign) UIImageView *contentView;
then the memory management is correct, but...
You are typically discouraged from assigning values to instance
variables anywhere other than in init methods. Elsewhere you should
use accessor methods, as this makes the memory management clear.
It would be better to do:
UIImageView *anImageView = [[UIImageView alloc] initWithFrame:...];
self.contentView = anImageView;
self.view = anImageView;
[anImageView release];
mmalc
_______________________________________________
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