Does calling a method inside a block that calls another method referring to self cause a retain cycle?

前端 未结 2 1224
臣服心动
臣服心动 2021-01-03 01:53

Can doFirst cause a retain cycle here?

@interface Example : NSObject
@property (nonatomic, strong) void (^block)();
@end

@implementation Exampl         


        
相关标签:
2条回答
  • 2021-01-03 02:39

    Unlike blocks, methods are not objects; they cannot hold a permanent reference to objects.

    Your code would not cause a retain cycle. The fact that the code inside doSecond references self explicitly does not mean that self would get retained an extra time. When your block calls doSecond, its self comes from the weakSelf reference inside doFirst.

    Note: When you store blocks as properties, use (nonatomic, copy) instead of (nonatomic, strong).

    0 讨论(0)
  • 2021-01-03 02:42

    No It won't. Because It just point to method which won't hold whatwhere inside methods which just an reference as like object.

    0 讨论(0)
提交回复
热议问题