1.copy与内存管理
char *cstr = "this is a c string";
NSString *str1 = [[NSString alloc] initWithUTF8String:cstr];
NSLog(@"str = %lu", [str1 retainCount]);
NSString *str2 = [str1 copy];
NSLog(@"str = %lu", [str1 retainCount]);
[str2 release];必须做一次release
char *cstr = "this is a c string";
NSString *str1 = [[NSString alloc] initWithUTF8String:cstr];
NSLog(@"str = %lu", [str1 retainCount]);
NSMutableString *str2 = [str1 mutableCopy];
NSLog(@"str = %lu", [str1 retainCount]);
[str2 release]; // 必须做一次release
网友评论