【发布时间】:2015-03-21 23:13:20
【问题描述】:
假设我想在一个块内做@synchronized(self)。我想这会导致一个保留周期,所以通常我们会像这样重写它:
-(void)myMethod
{
__weak TheClass * weakSelf = self;
dispatch_async(dispatch_get_main_queue(),
^{
TheClass * strongSelf = weakSelf;
if(strongSelf == nil)
{
return;
}
@synchronized(strongSelf)
{
//mutex code
}
}
}
我的问题是,当你以这种方式使用@synchronized 指令时,它是否等同于@synchronized(self)?
【问题讨论】:
标签: objective-c memory-management objective-c-blocks synchronized reference-cycle