Retain loops are way too easy with block/closures but could be prevented in Swift
| Originator: | raylillywhite | ||
| Number: | rdar://23238038 | Date Originated: | 23-Oct-2015 11:16 AM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | Reproducible: |
Summary: Retain loops are by far the number one reason for memory leaks, but a simple feature of Swift could almost completely eliminate them: Require the ownership of `self` to be explicitly specified in a block unless the block is only used for a `@noescape` block. Developers very rarely mistakenly choose to have `self` strongly retained to create the retain loops. Usually it's because we go back and modify something within a block and we use self without thinking about the capture semantics, or because we forgot to specify while we're writing the code. Having to explicitly type `[strong self]` would probably eliminate more than 90% of retain loops in most applications. I know that's a breaking change, but hopefully the code migrator would be able to handle making that transition easier. Steps to Reproduce: Expected Results: Actual Results: Version: Xcode 7.1 Notes: Configuration: Attachments:
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!