zoukankan      html  css  js  c++  java
  • iOS----------viewcontroller中的dealloc方法不调用

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

    当我们使用NSNotificationCenter方法,可以在viewDidLoad中添加监听,在dealloc中remove监听,但是有的时候我们发现,在退出这个vc的时候,系统不调用dealloc方法,造成这样的方法可能有以下几种原因(目前知道的):

    1、viewcontroller中存在定时器NSTimer

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

      self.timer = nil;//nil

     

    2、viewcontroller中有代理Delegate,需要设置delegate的时候,设置为weak

     

    @property (nonatomic,weakid<WorkHistoryDelegate>delegate;

    3、viewcontroller中有Block方法

    block会把它里面的所有对象强引用,包括当前控制器self,因此有可能会出现循环引用的问题。比如viewController中有个block属性,在block中又强引用了self或者其他成员变量,那么这个viewController与自己的block属性就形成循环引用,导致viewController无法释放。

     

        __weak typeof(self) weakSelf = self;

        [self.tableView tableViewAddUpLoadRefreshing:^{

     

    [weakSelf loadCommentListData];

     

        }];

  • 相关阅读:
    国外插画等形式美术网址
    jquery对联广告
    国外优秀PS网站
    web前端开发工程师
    有关HTML+CSS需注意的一些问题
    公积金账户余额
    什么是CSS Float?
    5款影楼后期制作软件
    国外优秀设计网站推荐
    jQuery跟随屏幕滚动的层
  • 原文地址:https://www.cnblogs.com/KiVen2015/p/9389329.html
Copyright © 2011-2022 走看看