• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: overt and covert retain-release question (instigated by UIViewController on iPhone)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >overt and covert retain-release question (instigated by UIViewController on iPhone) (From: Stuart Malin <email@hidden>)

  • Prev by Date: Re: tableView:objectValueForTableColumn:row not being called
  • Next by Date: Re: Setting up a main menu in a NIB(XIB)?
  • Previous by thread: Re: overt and covert retain-release question (instigated by UIViewController on iPhone)
  • Next by thread: Re: overt and covert retain-release question (instigated by UIViewController on iPhone)
  • Index(es):
    • Date
    • Thread