刚调试程序时发现一个很诡异的问题,我从ViewController A push进 ViewController B,在从B back时发现程序不会执行B里面的delloc(),很诡异的问题,因为按理说此时点击back是执行pop操作的,是会执行delloc()函数的,但经调试发现确实没有执行。
后来经过google发现,
The dealloc method was not being called if any of the references held by a viewcontroller were still in memory. |
timer=[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES];
这一句调用的时候对 target:self 进行了retain,这时候你pop回上一级,self的引用计数还剩1,所以铁定不会dealloc,我的解决办法是在- (void)viewWillDisappear:(BOOL)animated()函数里执行[timer invalidate];这样,self view计数器为0,当前view执行了delloc()。