I have a class with a property which is a weak reference to a block.
@interface BlockTest : NSObject
@property (nonatomic, weak) void(^testBlock)();
@end
At another point in the class I use this block like this:
- (void)foobar {
self.testBlock = ^{
[self doSomething];
};
}
The compiler (Apple LLVM 3.0) complains that there might be a retain cycle because self is strongly captured here. But I fail to see how this leads to a retain cycle because the block itself is a __weakreference, so it should be fine. If I understood ARC weak references correctly, when the -foobar method returns the block passed to self.testBlock should be deallocated (if not held elsewhere) and thus also release self.
What's the reason the compiler still thinks there might be a retain cycle?
nil. - newacctselfin a callback block of a method called onselfwithout triggering the warning. - Alfonso