@ "My String" is a literal string compiled into a binary file. When loading, it has a place in memory. The first line declares a variable pointing to this point in memory.
From the string programming guide:
The easiest way to create a string object in your source code is to use the Objective-C @ "..." construct:
NSString *temp = @"/tmp/scratch";
Note that when creating a string constant in this way, you should avoid using anything other than 7-bit ASCII characters. Such an object is created at compile time and exists at runtime of your programs. The compiler makes such an object constants unique to each module, and they are never freed, although you can save and free them like any other object.
The second line selects the line, taking this literal line. Note that the literal strings "My String" are the same. To prove this:
NSString *str = @"My String"; NSLog(@"%@ (%p)", str, str); NSString *str2 = [[NSString alloc] initWithString:@"My String"]; NSLog(@"%@ (%p)", str2, str2); NSString *copy = [str2 stringByAppendingString:@"2"]; NSLog(@"%@ (%p)", copy, copy);
Prints the same memory address:
2011-11-07 07:11:26.172 Craplet[5433:707] My String (0x100002268) 2011-11-07 07:11:26.174 Craplet[5433:707] My String (0x100002268) 2011-11-07 07:11:26.174 Craplet[5433:707] My String2 (0x1003002a0)
What it says is not only the first two lines of the same memory address, but if you do not change the code, it is the same memory address every time you run it. This is the same binary offset in memory. But not only the copy is different, but also different each time it is launched, as it stands out on the heap.
Abstract does not affect the above doc document. You can set them free, but they are never set free. Thus, they are not equal because both are auto-implemented strings, but they are both constants and the release is ignored.