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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to