Possible errors p 110


Correct me if i am wrong but:

Page 110, “By default, any outlet from your view controller to a subview is retained by that subview”.

Is this written badly or am i not getting the meaning? Should it not be retained by that view controller? However, that is only true if the outlet is retained, which it is not in CurrentTimeViewController.

Followed is the line that has this error “For example, CurrentTimeViewController retains a UILabel because it has the outlet timeLabel”. As stated previously this outlet needs to be retained for that to be true. In the example from the book the UILabel is simple assigned when the nib is loaded.

One more thing about this, the viewDidUnload code followed should not release the timeLabel, only set it to nil because of the same reason.

My bad, seems like the outlets are being retained by default.


Blah, yeah, the wording is off there. It should read:

“By default, any outlet from a view controller to a subview is retained by that view controller.” Of course, this can be generalized to say “By default, any object that is connected to an outlet is retained by the owner of that connection.” Any subview is also retained by its superview. Therefore, anytime you have an outlet connection to a subview, that subview has a retain count of 2 - one for its superview and one for its view controller.


I had a question regarding what is going on in the viewDidUnload method.

  • (void)viewDidUnload {
    NSLog(@“low memory issue”);
    [super viewDidUnload];
    [timeLabel release];
    timeLabel = nil;

Initially I missed the part about setting timeLabel to nil. When I simulated low-memory and then tried to load the time view again, the program dumped out. When I put in the nil call, everything works fine. Why is this?


This is a memory management thing. If you have a pointer to a UILabel object stored in timeLabel, and then you release that object and it gets destroyed, you need to set the pointer to that object to nil. If you don’t set the pointer called timeLabel to nil, it continues to point at what was once a UILabel object - but is now destroyed memory.

Make sure to keep the pointer variable that stores the location of an object and the object itself separate in your head and this becomes more clear.


I probably have a different printing of the book, but that paragraph is on page 114 for me, hehe.

I didn’t see a designated thread for errata (in the individual chapter forums at least), but I wanted to point out that in all the code samples in this chapter (Chapter 7 View Controllers) containing the -application:didFinishLaunchingWithOptions: method, the return statement is missing. If I didn’t have to manually enter that method in each time (my templates still use the older version of the method that returns void instead of a boolean value, even though I’m running v3.1.4 of Xcode…hopefully when I upgrade to Snow Leopard, the 3.2 build (or maybe even Xcode 4!) will take care of these details), I probably wouldn’t have even noticed.