2012-12-25 18:00 by v2m, 1171 阅读, 1 评论, 收藏, 编辑
以下全部在xCode 4.5,llvm 4.1的测试环境中 1.IBOUTLET 对于IBOUTLET必须是weak的说法,经过使用Instruments测试,使用strong修饰在arc开启的情况下完全没有任何内存遗留不释放的问题。 //yu IBOUTLET变量是系统处理xib时创建,并管理的,且生命周期长于controller,因此在controller 中对其使用weak也很正常 2.Toll-Free Bridging 桥归桥,路归路。 3.block __block __weak A* a = self; B = ^(){a....} 或者 __weak id weakSelf = self; block = ^() { id strongSelf = weakSelf; if (strongSelf != nil) { // do stuff with strongSelf } };
5.readonly @property (nonatomic, readonly) NSString *name; //yu 有默认为strong吗?默认atomic 6.autorelease { [self test]; NSLog(@"myString: %@",myString);// 他的说法这里在开启arc时是nil } -(void)test{ @autoreleasepool { NSString *string= [[NSString alloc] initWithFormat:@"First Name: %@", @"tom"]; NSLog(@"string: %@",string); myString=string; } } 对strong类型的对象赋值有所不同。 //yu 显然应该可以正常赋值啊,不会为nil啊。 //yu arc开启时,对变量赋值自动attain,局部变量超出作用域自动release。 //yu 但myString是成员变量啊。 7.对工程是否支持arc的判断 #if __has_feature(objc_arc) // do your ARC thing here #endif
#if defined(__has_feature) && __has_feature(objc_arc) // do your ARC thing here #endif
8.不确定性 UIColor *uicolor = [UIColor colorWithRed: 0.2 green: 0.3 blue: 0.4 alpha: 1.0]; CGColorRef color = uicolor.CGColor; [[self.view layer] setBackgroundColor: color]; //yu 在此函数返回前,uicolor都不会释放,color也可以正常使用。
|
|