0
votes

In ARC, if A hold a strong reference to B, and B holds a strong ref to A, there will be a retain cycle.

Will the code below also create a retain cycle?

    __weak MyClass *weakSelf = self;
    [self doSomething:^{

        weakSelf.someVariable = YES;

        [weakSelf doSomething:^{

            weakSelf.someVariable = YES;
        }];

    }];
2

2 Answers

2
votes

With ARC the weakSelf pointer is copied, but since it's weak, the copy of the pointer will not cause the retain count to be increased. So no, it doesn't create a retain cycle.

2
votes

No it won't. In fact, if you dont retain the object and for some reason the block would be called after the MyClass object gets deallocated, you end up with a runtime crash