Re: release and reference counting query
Re: release and reference counting query
- Subject: Re: release and reference counting query
- From: Roland King <email@hidden>
- Date: Fri, 07 Nov 2008 20:17:13 +0800
the iPhone documentation - I guess because it's recent, tends to use
properties quite a lot. You'll even find in the class description
documentation that things are documented as properties instead of
setXXX and XXX methods (and it tells you which are readwrite and
readonly etc.).
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.
take a look at the MoveMeAppDelegate.h file, you'll see that property
defined as I said as readwrite, retain and it's synthesized in the .m
file and released in dealloc().
I started off using the property syntax but I stopped again and I'm
long-winded and use the [ self setXXX: ] form instead because I find
for me it's easier to remember that I'm really calling a method on an
object. Your mileage may vary. Even if you define things as properties
you don't HAVE to use the 'dot' syntax if the other way makes it
clearer to you.
On Nov 7, 2008, at 7:59 PM, Calum Robertson wrote:
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
_______________________________________________
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