When the compiler sees @"Hello"
, it sticks a symbol in the .o file that says "hey, dev wants a string with contents "Hello"
. When the linker links together everything, it unique-ifies all the strings and emits a string table that contains all the strings that the code defined within.
So, in effect, the compiler is "allocating and initializing" the string instances at compile and link time.
They are actually stored in a special format that a particular subclass of the NSString
class cluster can encapsulate. When your app is run, the instances of this subclass already exist and are simply mapped into memory.
So, no, not allocated and initialized. But, yes, still objects in every sense of the word. The only caveat is that they ignore retain/release/autorelease and, thus, when you do NSString* foo = @"foo";
, technically that should also be retain
ed. But, by convention, no one ever bothers and that's just fine.