I've got the Apress book on iPhone dev, and I noticed this bit of code (I've modified/cut it down a bit to keep it short/simple):
Isn't the unconditional [msg release] incorrect? If we just assigned it to @"Blah blah" then we haven't really allocated anything, so there's no need to release it, right? Maybe the code should've done msg = [[NSString alloc] initWithString
"Blah blah"]; just to be safe?
Code:
if (...some condition...)
msg = [[NSString alloc] initWithFormat:@"Blah %@", someObj];
else
msg = @"Blah blah";
...some code...
[msg release];
Isn't the unconditional [msg release] incorrect? If we just assigned it to @"Blah blah" then we haven't really allocated anything, so there's no need to release it, right? Maybe the code should've done msg = [[NSString alloc] initWithString