iOS Controller退出后不能释放,不走dealloc方法

1、使用了计时器NSTimer,没有销毁

if (adTimer != nil) {
        [adTimer setFireDate:[NSDate distantFuture]];
        [adTimer invalidate];
        adTimer = nil;
    }

2、delegate定义为属性的时候,使用weak修饰符

@property (nonatomic,weak) id<GLGrowCountViewDelegate> delegate;

3、使用到block的地方,注意使用弱引用,避免强引用

//解决block强引用问题 宏
#define WeakSelf(weakSelf)  __weak __typeof(&*self)weakSelf = self;
#define StrongSelf(strongSelf)  __strong __typeof(&*self)strongSelf = weakSelf;

WeakSelf(weakSelf);
 [self progressHUDShowThenHideWithText:@"注册成功" Action:^{
        GLBindWXViewController *vc = [[GLBindWXViewController alloc] init];
        vc.isFromTeminalLogin = weakSelf.isFromTeminalLogin;
        vc.isLogoutToLogin = weakSelf.isLogoutToLogin;
        vc.isGuideToLogin = weakSelf.isGuideToLogin;
        vc.isTouristToLogin = weakSelf.isTouristToLogin;
        [weakSelf.navigationController pushViewController:vc animated:YES];}];

4、block中使用到了变量,把它定义为属性,用 weakself.属性 来调用

不用
@interface GLLevelDetailViewController ()
{
    NSInteger currentTypeID;
}
@property (nonatomic,copy) NSString *currentTypeID;

WeakSelf(weakSelf);
self.detailMedalButton = [GLButton buttonWithUrlImageWithFrame:CGRectMake(SCREENWIDTH - 40.0f*widthIPhone6 - medal_w, SCREENHEIGHT - medal_w - 10.0*widthIPhone6, medal_w, medal_w) Url:nil PlaceholderImage:@"hz_pic_default.png" ActionBlock:^{
        if ([GLSceneLessonDataManager sharedInstance].hzpic != nil) {
            [weakSelf showBigDetailMedalWithUrl:[GLSceneLessonDataManager sharedInstance].hzpic PassStatus:weakSelf.isAllPass TypeID:weakSelf.currentTypeID];
        }
    }];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 目录 属性 修饰词 循环引用 typeof与typedef 1. 属性 objc所有类和对象都是c结构体,cate...
    Ryan___阅读 2,732评论 0 1
  • 基础 1. 为什么说Objective-C是一门动态的语言? 2. 讲一下MVC和MVVM,MVP? 3. 为...
    波妞和酱豆子阅读 8,651评论 0 46
  • 1. 单例写法 单例模式确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例。 一般情况下, 如果一个...
    sellse阅读 4,622评论 0 1
  • 把网上的一些结合自己面试时遇到的面试题总结了一下,以后有新的还会再加进来。 1. OC 的理解与特性 OC 作为一...
    AlaricMurray阅读 7,382评论 0 20
  • 我从小就听你们的话 什么都听 换来今年暑假你当着我的面说 “你们这批独生子女有很大的心理问题” 当着我的面啊 你这...
    佛爷和眼镜都不能少阅读 3,547评论 2 0