Skip to content

Instantly share code, notes, and snippets.

@mikekavouras
Last active September 3, 2016 04:21
Show Gist options
  • Save mikekavouras/2020f6e40ab590d8d6ff2b472c683592 to your computer and use it in GitHub Desktop.
Save mikekavouras/2020f6e40ab590d8d6ff2b472c683592 to your computer and use it in GitHub Desktop.
Memory Leak
// Passing a closure with a reference to `self` which is ultimately stored as
// an instance property. Strong reference = retain cycle.
collectionView?.addInfiniteScrollWithHandler { collectionView in
self.update(false)
}
// Fixed: Make sure `self` that is being passed is explicitly marked as `weak`
// to force a weak reference.
collectionView?.addInfiniteScrollWithHandler { [weak self] collectionView in
self?.update(false)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment