weakSelf和strongSelf

    __weak typeof(self)weakSelf=self;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        __strong typeof(weakSelf)strongSelf=weakSelf;
        
        [strongSelf doSomething];
        
    });

 

 

weak typeof(self)weakSelf=self;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

        __strong typeof(weakSelf)strongSelf=weakSelf;
        
        [strongSelf doSomething];
        
    });

 

weakSelf是为了block不持有self,避免循环引用,而再声明一个strongSelf是由于一旦进入block执行,就不容许self在这个执行过程当中释放。block执行完后这个strongSelf会自动释放,没有循环引用问题。html

相关文章
相关标签/搜索