see this code and its log:
NSString *string1 = [NSString stringWithString:@"a"]; NSString *string2= @"a"; NSLog(@"String1: %p", string1); NSLog(@"String2: %p", string2); 2012-03-22 13:21:49.433 TableDemo[37385:f803] String1: 0x5860 2012-03-22 13:21:49.434 TableDemo[37385:f803] String2: 0x5860
as you see, [NSString stringWithString:@"a"]; does not create a new line, it uses the string literal @ "a". And string literals cannot be freed.
Try using the NSMutableString code and you will see a failure.
source share