I’m by no means an expert, but here’s the way I understand this:
When you click the button “Insert” in your program, it calls the createNewItem: method.
The createNewItem: method checks to see if an array list named todoItems exists, if not it creates one with the line : todoItems = [NSMutableArray array]; and then adds an object to the todoItems array with the line : [todoItems addObject:@“New Item”]; So now you have an array object named todoItems in memory that contains your important data.
The problem is that if nobody “owns” this object, it will be deallocated at some point in the future. How do you know if somebody “owns” the object? Have you or another object ever sent it the “retain” message? If not, nobody owns it. So the problem is that since nobody owns todoItems, then as Aaron puts it, the object continues it’s death march to deallocation. And when the object gets deallocated, it’s gone from memory and when the program wants to use it again (ie - to display the To Do List) it’s not there and causes the program to crash!
When you send the retain message to the todoItems object - [todoItems retain], it increases it’s retain count by 1 and ensures that the object will stick around forever, until you specifically send it the release method - [todoItems release] In this program you would never send [todoItems release] because you always need this object for the program, as it holds the entire contents of the program and the program can’t run without it.
At first I found this entire concept REALLY confusing. And apparently memory management is the #1 stumbling block for people learning Objective C. This mess is what ARC fixes. With ARC (automatic reference counting) you don’t need to worry about retain and release because XCode does it all for you. However ARC isn’t supported on OSX 10.6 Snow Leopard with XCode 4.2 for Mac apps, only iOS apps. On OSX 10.7 Lion with XCode 4.2, ARC works on both Mac apps and iOS apps.
I hope that helps - like I said at the top, I’m not an expert, but this is my understanding of it. If you have this book in e-format like Kindle, do a search for the phrase “Death March” and re-read that chapter again after 2 or 3 cups of coffee and all will become clear.