Re: release and reference counting query
Re: release and reference counting query
- Subject: Re: release and reference counting query
- From: Marc Stibane <email@hidden>
- Date: Tue, 18 Nov 2008 19:33:59 +0100
-- sorry, repost (went to the wrong list yesterday)
Am 07.11.2008 um 13:17 schrieb Roland King:
On Nov 7, 2008, at 7:59 PM, Calum Robertson wrote:
Below is a snippet of code from the "Creating an iPhone
Application" document from the iPhone DevCenter.
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// Set up the view controller
UIViewController *aViewController = [[UIViewController alloc]
initWithNibName:@"MoveMeView" bundle:[NSBundle
mainBundle]];
self.viewController = aViewController;
[aViewController release];
...
}
In this case whatever self is has declared viewController as a
readwrite/retain property, so self.viewController = aViewController
is the same as [ self setViewController:aViewController ] and
perhaps you're happier with that syntax and realizing that the
implementation of setViewController would retain the object and the
dealloc() will eventually release it.
Lets forget for a moment that the dealloc never get's called at all on
the iPhone - when you press the home button the app just quits and
iPhoneOS throws away all alloc'ed memory at once instead of letting
the app do it one by one which would last longer with the same result
- but anyway, what's the reason for defining a local variable
aViewController to receive the UIViewController pointer, then copying
that to the instance variable with a setter method which increases the
retain count, then decrease the retain count again - instead of just
using the instance variable?
viewController = [[UIViewController alloc]
initWithNibName:@"MoveMeView" bundle:[NSBundle
mainBundle]];
since "viewController" is a member of the class, you don't need the
"self.".
So why the local var?
3 lines of code instead of 1...
Isn't a main goal of Cocoa to write *less* code?
--
In a world without walls and fences,
who needs windows and gates?
_______________________________________________
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