<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi. I’ve come to this issue too.</div><div class="">I thought that current Swift memory model is good enough to solve this in the other way. I've put self (aka ExecutionContext) as an argument to map/filter/etc. This looked like I'm binding execution to the specified context. It might sound odd, but it actually fits nicely into some kind of actor model. It opened such possibilities as automatic cancellation of async execution if there is no context that will use results of the execution.</div><div class="">Ended up developing a library that incorporates this idea <a href="https://github.com/AsyncNinja/AsyncNinja" class="">AsyncNinja</a> sometimes looks even <a href="https://github.com/AsyncNinja/AsyncNinja#comparison-with-rxswift" class="">better then RxSwift</a>. I also wrote an <a href="https://medium.com/@AntonMironov/moving-to-nice-asynchronous-swift-code-7b0cb2eadde1#.mfw3lbxiq" class="">article</a> that shows advantages of the approach.</div><div class="">Please tell me if it makes sense for you.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Anton Mironov</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Feb 20, 2017, at 1:22 PM, Lauri Lehmijoki via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">So, I'd like to ask you two things:</div><div class=""><br class=""></div><div class="">A) By default, why the Swift closure captures values strongly?</div><div class="">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 class=""><br class=""></div><div class="">Regards</div><div class="">Lauri</div></div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>