I’ve been reading the “Beginning iPhone 4 Development” book and they have one tutorial for using navigation controllers. In this tutorial we push a view controller (named childController) onto the view. But since we don’t want to “expose” this controller for other classes we have not created any accessor methods for it. So in the viewDidUnload the authors have written:
- (void)viewDidUnload {
[childController release], childController = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
I really don’t understand the comma sign after the release? This code is actually working for me. I haven’t received any errors or memory leaks.
But to my understanding shouldn’t it be like this instead:
- (void)viewDidUnload {
[childController release];
childController = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
this is plain C, comma operator aimed at “sequencing” expressions. actually, in this case, it is completely equivalent to:
the only thing that changes is readability (for worse or better, it depends…)
but in general the sequencing operator evaluates to the last statement’s value (i.e., values of all operands are discarded except the last one).
c would be 2 after execution of this statement.
EDIT: from the link I added:
edit: a better example:
this will first print:
then assign 3 to b.