• 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
release and reference counting query
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: release and reference counting query
      • From: Roland King <email@hidden>
    • Re: release and reference counting query
      • From: Filip van der Meeren <email@hidden>
  • Prev by Date: RE: Link error: _open$UNIX2003
  • Next by Date: Re: release and reference counting query
  • Previous by thread: Re: UI help: visibly disabling NSImageView
  • Next by thread: Re: release and reference counting query
  • Index(es):
    • Date
    • Thread