iOS----------viewcontroller中的dealloc方法不调用

ios的viewcontroller生命周期是 init -> loadView -> viewDidLoad -> viewWillAppear -> viewDidAppear -> viewWillDisappear -> viewDidAppear -> viewDidUnload -> deallocios

当咱们使用NSNotificationCenter方法,能够在viewDidLoad中添加监听,在dealloc中remove监听,可是有的时候咱们发现,在退出这个vc的时候,系统不调用dealloc方法,形成这样的方法可能有如下几种缘由(目前知道的):app

 

一、viewcontroller中存在定时器NSTimeratom

  [self.timer invalidate];//结束定时spa

 

  self.timer = nil;//nil代理

 

二、viewcontroller中有代理Delegate,须要设置delegate的时候,设置为weak对象

 

@property (nonatomic,weakid<WorkHistoryDelegate>delegate;生命周期

 

三、viewcontroller中有Block方法rem

block会把它里面的全部对象强引用,包括当前控制器self,所以有可能会出现循环引用的问题。好比viewController中有个block属性,在block中又强引用了self或者其余成员变量,那么这个viewController与本身的block属性就造成循环引用,致使viewController没法释放。it

 

    __weak typeof(self) weakSelf = self;io

    [self.tableView tableViewAddUpLoadRefreshing:^{

 

[weakSelf loadCommentListData];

 

    }];

相关文章
相关标签/搜索