reference-cycle

Does assigning a weak pointer to a strong pointer copy the object?

自作多情 提交于 2019-12-12 03:45:20
问题 The common pattern to avoid capturing self within a Block is to create a weak self outside the Block and use this to create a "locally strong" version of self within the Block (inner self). __weak ClassX *weakSelf = self; [someOtherObject methodThatTakesCOmpletionBlock: ^{ ClassX innserSelf = weakSelf; //innserSelf creation? [someObject send:innerSelf.prop;}]; What happens when the innserSelf creation line is executed? Is innerSelf a copy of self at the time the method

How to remove strong reference cycle from closure from method?

孤街醉人 提交于 2019-11-26 18:35:26
问题 Here I have some examples for closure strong reference cycles. If I assign a closure to a stored property, I can use a closure capture list to make the captured reference unowned/weak. But if I assign a method to a stored property closure or assign the method to a closure in the outer scope I can not use a capture list. What can I do to remove the reference cycle in the last two cases? Example to create and avoid strong reference cycle with capture list with closure only internal class