美文网首页
NSTimer的循环引用

NSTimer的循环引用

作者: 吓死宝宝了啊 | 来源:发表于2017-09-14 21:14 被阅读4次

使用的NSTimer的时候一定要弱引用timer对象,否则会造成循环引用。

[NSTimer scheduledTimerWithTimeInterval:1 repeats:YES block:^(NSTimer * _Nonnull timer) {

NSLog(@"sds");

[weakSelf repeat];

}];此方法创建的block使用self会造成循环引用

[NSTimer scheduledTimerWithTimeInterval:1 target:weakSelf selector:@selector(repeat) userInfo:nil repeats:YES];此方法创建的即使weak引用还是不会释放


相关文章

网友评论

      本文标题:NSTimer的循环引用

      本文链接:https://www.haomeiwen.com/subject/nskjsxtx.html