@weakify, @strongify

ARC supposedly does away with reference counting. However, blocks introduce a small wrinkle.

When you reference self¬†in a block you make a strong reference to it which encourages leaks as you end up with objects (including¬†View Controllers) hanging around beyond when they’re needed.

The solution is to define a weak reference before the block and use that. Inside the block you convert it to a strong reference. We don’t have a proper strong reference outside the block so it decrements as it should do. However, it’s a pain (see the first part of the linked-to post).

This is where the @weakify(self) technique makes things simple and easy. See the second part of this post!


Leave a Reply

Your email address will not be published. Required fields are marked *