NSString* str = @"foo";
str = [NSString stringWithFormat:@"%@%@", str, @"bar"];
Will @"foo" be autoreleased? That is, will its retain count go to 0 when str is reassigned?
NSString* str = @"foo";
str = [NSString stringWithFormat:@"%@%@", str, @"bar"];
Will @"foo" be autoreleased? That is, will its retain count go to 0 when str is reassigned?
Yes, it will be released. You didn't alloc/init/new/copy it.
Edit: I suppose it would be more correct to say "no, it won't leak", since it is in fact a constant. The alloc/init/new/copy advice still applies though.
@"foo" is a compile-time constant object in memory, so its retain count is irrelevant. It is safe to reassign this way, even when reusing it in a stringWithFormat: as you are doing.