release and reference counting query
release and reference counting query
- Subject: release and reference counting query
- From: Calum Robertson <email@hidden>
- Date: Fri, 07 Nov 2008 11:59:20 +0000
Hi,
Below is a snippet of code from the "Creating an iPhone Application" document from the iPhone DevCenter. I'm not clear as to why this works. My understanding is that when [UIViewController alloc] is executed, the retain count is 1 and then when [aViewController release] is called, the retain count reduces to zero. Does self.viewController not then reference deallocated memory? I thought I had got the hang of retain / release but this snippet confused me...
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// Set up the view controller
UIViewController *aViewController = [[UIViewController alloc]
initWithNibName:@"MoveMeView" bundle:[NSBundle mainBundle]];
self.viewController = aViewController;
[aViewController release];
// Add the view controller's view as a subview of the window
UIView *controllersView = [viewController view];
[window addSubview:controllersView];
[window makeKeyAndVisible];
}
C
_______________________________________________
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