1.copy與內(nèi)存管理
- 淺拷貝
- 原對象引用計數(shù)器+1
- 必須對原對象進(jìn)行釋放
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
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者