NSString的retainCount
NSString * aa = [[NSString alloc] init];
NSLog(@"%d",[aa retainCount]);
输出:-1 (_NSCFConstantString *)
NSString * aa = [NSString string];
NSLog(@"%d",[aa retainCount]);
输出:-1 (_NSCFConstantString *)
NSString * aa = [[NSString alloc]initWithString:@"23"];
NSLog(@"%d",[aa retainCount]);
输出:-1 (_NSCFConstantString *)
NSString * aa = [NSString stringWithString:@"23"];
NSLog(@"%d",[aa retainCount]);
输出:-1 (_NSCFConstantString *)
NSString *aa = @"This is a String!";
NSLog(@"%d",[aa retainCount]);
输出:-1 (_NSCFConstantString *)
NSString *temp = @"/tmp/scratch";
Note that, when creating a string constant in this fashion, you should avoid using anything but 7-bit ASCII characters. Such an object is created at compile time and exists throughout your program’s execution. The compiler makes such object constants unique on a per-module basis, and they’re never deallocated, though you can retain and release them as you do any other object.
NSString * aa = [[NSString alloc]initWithUTF8String:"23"];
NSLog(@"%d",[aa retainCount]);
输出:1 (_NSCFString *)
NSString * aa = [NSString stringWithUTF8String:"23"];
NSLog(@"%d",[aa retainCount]);
输出:1 (_NSCFString *)
NSString * aa = [[NSString alloc] initWithCString:"123" encoding:NSUTF8StringEncoding];
NSLog(@"%d",[aa retainCount]);
输出:1 (_NSCFString *)
NSString * aa = [NSString stringWithCString:"23" encoding:NSUTF8StringEncoding];
NSLog(@"%d",[aa retainCount]);
输出:1 (_NSCFString *)
NSString * aa = [[NSString alloc] initWithFormat:@"%@",@"23"];
NSLog(@"%d",[aa retainCount]);
输出:1 (_NSCFString *)
NSString * aa = [NSString stringWithFormat:@"%d",23];
NSLog(@"%d",[aa retainCount]);
输出:1 (_NSCFString *)