views:

42

answers:

1

This question is related to this one, but simpler. [I think I may be close to the end of these dumb questions and can get down to serious business :)].

I have a retain property and set to it like this:

UINavigationController *thing = [[UINavigationController alloc] initWithRootViewController:one];
    // thing's retain count is one
navController = thing;
    // thing's retain count is still one!
[thing release];
    // now retain count is zero, which is wrong

I cannot understand why the retain count gets to zero. navController is defined as

@property (nonatomic, retain) UINavigationController *navController;

Shouldn't the property increase the retain count by one?

+4  A: 

The problem is: you are assigning directly to the property's underlying instance variable instead of calling the setter. The property magic is not triggered this way. Try

self.navController = thing;

instead (remaining code needs no change).

Dirk
Oh my that was dumb. Thanks
Yar
Cool, now I can finally do this `self.navController = [[[UINavigationController alloc] initWithRootViewController:one] autorelease];` which is what I was going for. Thanks again.
Yar