iOS 未销毁常见原因整理

1 强引用 timer

  • fix: 未调用invalidate 且 置为 nil

2 页面退出时 perform after 仍未执行

  • eg: [self performSelector:@selector(sel) withObject:nil afterDelay:30];
  • fix: [NSObject cancelPreviousPerformRequestsWithTarget:self];

3 页面退出时 dispatch after 仍未执行

  • eg: dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 50), dispatch_get_main_queue(), ^{})
  • fix: __weak typeof(self) weakSelf = self;
    __weak typeof(self) weakSelf = self;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        __strong typeof(self) self = weakSelf;
//        [self actionTimer:100];
    });
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容