[swift-evolution] Should explicit `self.` be required when providing method as closure?

Charles Srstka cocoadev at charlessoft.com
Sat Mar 4 11:35:52 CST 2017


> On Mar 4, 2017, at 1:09 AM, David Hart via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I encountered this precise memory leak in my code a few days ago, so I sympathize. A second solution would be to drop function references. I think a core team member suggested it on another thread.

If I had to guess, I’d surmise that it's probably the single most common memory leak in Swift and modern Objective-C code. What I wish is that it were possible to get rid of implicit captures altogether—instead of just inserting [weak self] when you *don’t* want to capture something strongly, also require [strong self] when you do. Referencing self otherwise causes an error. We’d never get away with it now, though, with the source compatibility promise in place.

Charles

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170304/bde11fcf/attachment.html>


More information about the swift-evolution mailing list