for (int i = 0; i < 1000; i++) {//100次不会闪退,次数少
dispatch_async(dispatch_get_global_queue(0, 0), ^{
people.name = [NSString stringWithFormat:@"asjkdhaksjdhkasd"];//__NSCFString
NSLog(@"%@",[people.name class]);
});
}
//当字符串长的时候,用__NSCFString,是一个变量,会并发 set方法 并发release闪退
-(void)setName:(NSString *)name{
if (_name != name) {
[_name release];
_name = [name retain];
}
return _name;
}
//当字符串短的时候用NSTaggedPointerString,是一个常量,指向同一个常量区,不会闪退
for (int i = 0; i < 1000; i++) {
dispatch_async(dispatch_get_global_queue(0, 0), ^{
people.name = [NSString stringWithFormat:@"123456789"];//NSTaggedPointerString
NSLog(@"%p",people.name);
NSLog(@"%@",[people.name class]);
});
}
网友评论