iOS笔记系列目录
- weak润饰的指针变量,在指向的内存地址销毁后,会在Runtime的机制下,主动置为nil。
- _Unsafe_Unretain不会置为nil,容易呈现悬垂指针,产生解体。然而_Unsafe_Unretain比__weak效率高。
@interface MyClass()
//@property (nonatomic, strong) NSMutableArray *array;
//@property (nonatomic, weak) NSMutableArray *array;
@property (nonatomic, unsafe_unretained) NSMutableArray *array;
@end
@implementation MyClass
- (void)test {
self.array = @[@"1",@"2"].mutableCopy;
void (^block)(void) = ^ {
//应用unsafe_unretained上面这行会产生解体,self.array成了僵尸对象
NSLog(@"%@",self.array);
};
block();
NSLog(@"---");
}
发表回复