The replacement code is incorrect and thus illustrates the problem that Apple is trying to prevent. Here is your code:
self.navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController]; [self.view addSubview:[navigationController view]]; [navigationController release];
You left me. in your links. Perhaps you wanted to access ivar directly, but in this case you created a very confusing code by mixing accessors and direct access to IVAR (and violated the basic rule using direct access to IVAR outside the accessor). If not, then you intended to write this:
self.navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController]; [self.view addSubview:[self.navigationController view]]; [self.navigationController release];
This last line is very wrong. Never send - select the result of a method call. So no, the way you do this is wrong.
However, Apple and I do not agree on how to do this. Here is how I do it:
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease; [self.view addSubview:[self.navigationController view]];
I like -autorelease because I find that it prevents errors. The more the alloc and release function is allocated, the more likely it is that the developer will introduce a memory leak (for example, by adding a "return"). autorelease avoid this by keeping the save and release together, making the intention to use this as a temporary variable more understandable and, as a rule, greatly simplifies the code review.
Apple generally disagrees with me in its sample code because they emphasize performance using release and outsourcing. I believe that this is an incorrect optimization, since this object will not be freed during this cycle of the cycle in any case (therefore, memory is not saved), and I believe that a very small decrease in the performance of auto-advertising is more compensated by a decrease in memory leaks due to improper use release.
The discussion with auto-advertising and the release is filled with shades of gray (of course, I use the release directly in the cycles), and different developers have different approaches, but your replacement code is not the way to do it anyway.