标签:
.h文件 @interface myclass:NSObject @property(nonatomic,retain)NSArray*MyArray; @end
.m文件 @implementation myclass -(void)viewDidLoad { [superviewDidLoad]; _MyArray=[[NSArrayalloc]initWithObjects:@"1",nil]; NSLog(@"%lu",(unsignedlong)[self.MyArray retainCount]);//输出1 self.MyArray=[[NSArrayalloc]initWithObjects:@"1",nil]; NSLog(@"%lu",(unsignedlong)[self.MyArray retainCount]);//输出2 我的理解是 self.MyArray=[[NSArrayalloc]initWithObjects:@"1",nil]; 相当于 NSArray*a=[[NSArrayalloc]initWithObjects:@"1",nil]; self. MyArray =a; 而self.MyArray会调用myArray的set方法, -(void)setMyArray:( NSArray *)Array { if(Array!= MyArray) { [MyArray release]; MyArray =[Array retain]; } } }
标签:
原文地址:http://www.cnblogs.com/shanyimin/p/4228728.html