differing methods of alloc / init / retaining an object in objective-c

Posted by taber on Stack Overflow See other posts from Stack Overflow or by taber
Published on 2010-06-01T06:26:45Z Indexed on 2010/06/01 6:33 UTC
Read the original article Hit count: 420

In several pieces of sample objective-c code I've seen people create new objects like this:


RootViewController *viewController = [[RootViewController alloc] init];
self.rootViewController = viewController; // self.rootViewController is a (nonatomic,retain) synthesized property
[viewController release];
[window addSubview: [self.rootViewController view]];

Is that any different "behind the scenes" than doing it like this instead?


self.rootViewController = [[RootViewController alloc] init];
[window addSubview: [self.rootViewController view]];

Seems a bit more straightforward/streamlined that way so I'm wondering why anyone would opt for the first method.

Thanks!

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone-sdk