The compiler is smarter than you.
It sees @"Hello world"
and thinks “Aha! A constant string!”
It then sees [[NSString alloc] initWithString:@"Hello world!"]
and thinks “Aha! An immutable object created with a constant string!”
It then collapses both of them down into a single NSConstantString
, which has a retainCount
of UINT_MAX
, so that it can never be released.