• 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: Beginner Question Re: Memory Management
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Beginner Question Re: Memory Management


  • Subject: Re: Beginner Question Re: Memory Management
  • From: Graham Cox <email@hidden>
  • Date: Tue, 23 Jun 2009 12:47:44 +1000


On 23/06/2009, at 6:39 AM, Daniel Torrey wrote:

I'm looking at some sample iPhone code, and in the app delegate's applicationDidFinishLaunching method, I see

// Set up the view controller
MyViewController *aViewController = [[MyViewController alloc] initWithNibName:@"HelloWorld" bundle:[NSBundle mainBundle]];
self.myViewController = aViewController;
[aViewController release];


I'm a little confused - I see an allocation, followed by an assignment, followed by a release. I think that the assignment is really a call to a setter - the myViewController field is created automagically using the @property/@synthesize syntax.

Since a release was sent to aViewController, what keeps that object from being nuked at the end of the run loop? There must be another retain happening somewhere, right?


Have a look at the definition for the property myViewController - it should include the 'retain' attribute, which tells you that the object is retained when it is assigned. In which case, it won't be nuked.

I don't think you can see the code generated by @synthesise, as it probably doesn't exist as Objective-C anywhere - but you can disassemble it. I could be wrong though...

--Graham


_______________________________________________

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: Beginner Question Re: Memory Management
      • From: WT <email@hidden>
References: 
 >Beginner Question Re: Memory Management (From: Daniel Torrey <email@hidden>)

  • Prev by Date: IKImageBrowserView setSelectionIndex not selecting
  • Next by Date: stepping in unit test
  • Previous by thread: Beginner Question Re: Memory Management
  • Next by thread: Re: Beginner Question Re: Memory Management
  • Index(es):
    • Date
    • Thread