Closed joeljfischer closed 9 years ago
@joeljfischer I think this SO post is related to what you were describing: Strong To Weak Reference
Yup, that describes it. It's also described in WWDC 2012 Session 712. This links to the PDF which you can only see logged in to Apple's dev site. See page 105.
Fixed in #316
Accessing iVars within blocks causes an implicit capture of self, which will lead to a retain cycle. The library needs to be audited for these issues. Below is one such:
(Note this is a bad example, since self doesn't actually capture this block)
Here, both
messageList
andatBottom
are iVars, which means that their calls actually look likeself->messageList
. This is an implicit capture of self and a retain cycle. One way to resolve this is to create a "weak" self outside of the block using something like__weak typeof(self) weakSelf = self
, then within the block, recapturing theweakSelf
as a strong, but scoped variable that will be released at the end of the block.Simply using the
weakSelf
could mean that it is released out from under us in the middle of the block. So within the block we would have__strong typeof(self) strongSelf = weakSelf
. Then to access the iVars, properties, call methods, etc. we would reference the strongSelf, like so:[strongSelf->messageList addObject:dictionary]
.