Re: release and reference counting query
Re: release and reference counting query
- Subject: Re: release and reference counting query
- From: Andy Lee <email@hidden>
- Date: Tue, 18 Nov 2008 14:05:20 -0500
On Nov 18, 2008, at 1:33 PM, Marc Stibane wrote:
Am 07.11.2008 um 13:17 schrieb Roland King:
On Nov 7, 2008, at 7:59 PM, Calum Robertson wrote:
Below is a snippet of code from the "Creating an iPhone
Application" document from the iPhone DevCenter.
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// Set up the view controller
UIViewController *aViewController = [[UIViewController alloc]
initWithNibName:@"MoveMeView" bundle:[NSBundle
mainBundle]];
self.viewController = aViewController;
[aViewController release];
...
}
[...]
what's the reason for defining a local variable aViewController to
receive the UIViewController pointer, then copying that to the
instance variable with a setter method which increases the retain
count, then decrease the retain count again - instead of just using
the instance variable?
The above is not an init method and should not assume that it is
performing the first assignment to an ivar. For all you know, a value
may have been assigned to the ivar by the init method, or by some code
that executed between the init method and this method. The safer
thing to do is use the accessor method to release any such value if
necessary.
Even if this were occurring in an init method, if the ivar happened to
be an inherited one, it would make sense to use an accessor to set it
in case the inherited init method assigned a value to the ivar that
needs to be released.
--Andy
_______________________________________________
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