For NSString, we can use
-
NSString *str = [[NSString alloc] initWithString:@”hi”]
-
NSString *str = [NSString stringWithString:@”hi”];
-
NSString *str = @”hi”;
Can someone pls told me in the form of point 3, whether str own @”hi”? I mean whether I need to [str release] when clean up?
Thanks
for point 1, yes, I need; for point 2, no, I don’t
For point 3?
No, you don’t need to release it.
String literal (that’s what you have in case 3) are created in compile time and their lifetime is the lifetime of your application. You can also easily check that release/retain operations do not affect their retain count (try to NSLog retainCount property and you’ll see that)