<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>It's important to note that strong captures by default are correct and not the issue here. It is reference cycles that are the problem. This feature has been requested before, and SR-1807 has been filed for it. </div><div><br></div><div>(For what it's worth, I started working on this a while ago, and a branch tracking this is here: <a href="https://github.com/apple/swift/compare/master...CodaFi:hammer-and-cycle">https://github.com/apple/swift/compare/master...CodaFi:hammer-and-cycle</a>).</div><div><br><div>~Robert Widmann</div></div><div><br>2017/02/20 6:22、Lauri Lehmijoki via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> のメッセージ:<br><br></div><blockquote type="cite"><div><div dir="ltr">I'm developing an application where we use RxSwift heavily. RxSwift is a stream library. Consequently, closures that we pass to its combinators often live infinitely (this is because one can use RxSwift to represent infinitely long sequences in time). <div><br></div><div>Closures with infinite lifespan have implications for the question "what is the best reference capture mode for closures". My experience is that in RxSwift applications, the current default (strong) is almost always suboptimal. It leads to difficult-to-detect memory leaks and introduces a "gotcha" factor to programmers who are new to Swift. I'd prefer the default to be weak capture.<div><br></div><div>So, I'd like to ask you two things:</div><div><br></div><div>A) By default, why the Swift closure captures values strongly?</div><div>B) Should we add a compiler option that, when turned on, would emit a warning if a closure strongly captures a class instance?</div><div><br></div><div>Regards</div><div>Lauri</div></div></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>