最近做了一些尝试
遇到一个问题
我在ViewController中有两个property为
@property (weak, nonatomic) UKTextField *myTextField;
@property (weak, nonatomic) Person *person;
UKTextField为继承UITextField的类别
Person为自己定义的类别
两个类别我都有覆写dealloc的方法
让两个物件被回收时可以显示Log
测试如下
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"viewDidLoad Start");
//Assigning retained object to weak variable;
//object will be released after assignment
myTextField = [[UKTextField alloc] init];
//Assigning retained object to weak variable;
//object will be released after assignment
person = [Person new];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(@"viewWillAppear Start");
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSLog(@"viewDidAppear Start");
}
Log内容出现顺序如下
1.viewDidLoad Start
2.Person Dealloc
3.viewWillAppear Start
4.UKTextField dealloc
5.viewDidAppear Start
问题:
将UKTextField与Person皆设定为weak
就ARC来说当weak的物件应该再被指派完之后应该在viewDidLoad就会被回收了
但为什么UKTextField会在viewWillAppear才会被回收呢??