<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important">I disagree with dropping function references in general, but I do agree with limiting partially applied method references.</p>
<p style="margin:0px 0px 1.2em!important">In <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">@escaping</code> arguments, adding <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">self.</code> won’t add enough evidence that it actually creates a closure with capture.<br>Even in non-escaping context, I find plain method references odd:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="hljs language-swift" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248)"><span class="hljs-func"><span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">func</span> <span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold">square</span><span class="hljs-params">(<span class="hljs-number" style="color:rgb(0,128,128)">_</span> x: Int)</span> -> <span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold">Int</span> </span>{ … }
(<span class="hljs-number" style="color:rgb(0,128,128)">1</span>...<span class="hljs-number" style="color:rgb(0,128,128)">10</span>).<span class="hljs-built_in" style="color:rgb(0,134,179)">map</span>(square) <span class="hljs-comment" style="color:rgb(153,153,136);font-style:italic">// totally ok with that</span>
<span class="hljs-class"><span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">class</span> <span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">SomeClass</span> </span>{
<span class="hljs-func"><span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">func</span> <span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold">foo</span><span class="hljs-params">(<span class="hljs-number" style="color:rgb(0,128,128)">_</span> x: Int)</span> -> <span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold">Int</span> </span>{ … }
<span class="hljs-func"><span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">func</span> <span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold">bar</span><span class="hljs-params">()</span> </span>{
(<span class="hljs-number" style="color:rgb(0,128,128)">1</span>...<span class="hljs-number" style="color:rgb(0,128,128)">10</span>).<span class="hljs-built_in" style="color:rgb(0,134,179)">map</span>(foo) <span class="hljs-comment" style="color:rgb(153,153,136);font-style:italic">// what??</span>
(<span class="hljs-number" style="color:rgb(0,128,128)">1</span>...<span class="hljs-number" style="color:rgb(0,128,128)">10</span>).<span class="hljs-built_in" style="color:rgb(0,134,179)">map</span>(<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">self</span>.foo) <span class="hljs-comment" style="color:rgb(153,153,136);font-style:italic">// ok</span>
someControl.addHandler(<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">self</span>.foo) <span class="hljs-comment" style="color:rgb(153,153,136);font-style:italic">// should be error if @escaping?</span>
}
}
</code></pre>
<p style="margin:0px 0px 1.2em!important">2017-03-04 10:09 GMT+03:00 David Hart via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>:</p>
<p style="margin:0px 0px 1.2em!important"></p><div class="markdown-here-exclude"><p></p><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">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.</blockquote><p></p></div><p style="margin:0px 0px 1.2em!important"></p>
<div title="MDH:SSBkaXNhZ3JlZSB3aXRoIGRyb3BwaW5nIGZ1bmN0aW9uIHJlZmVyZW5jZXMgaW4gZ2VuZXJhbCwg
YnV0IEkgZG8gYWdyZWUgd2l0aCBsaW1pdGluZyBwYXJ0aWFsbHkgYXBwbGllZCBtZXRob2QgcmVm
ZXJlbmNlcy48ZGl2Pjxicj48ZGl2PkluIGBAZXNjYXBpbmdgIGFyZ3VtZW50cywgYWRkaW5nIGBz
ZWxmLmAgd29uJ3QgYWRkIGVub3VnaCBldmlkZW5jZSB0aGF0IGl0IGFjdHVhbGx5IGNyZWF0ZXMg
YSBjbG9zdXJlIHdpdGggY2FwdHVyZS48L2Rpdj48ZGl2PkV2ZW4gaW4gbm9uLWVzY2FwaW5nIGNv
bnRleHQsIEkgZmluZCBwbGFpbiBtZXRob2QgcmVmZXJlbmNlcyBvZGQ6PGJyPjxkaXY+PGRpdj48
YnI+PC9kaXY+PGRpdj5gYGBzd2lmdDwvZGl2PjxkaXY+ZnVuYyBzcXVhcmUoXyB4OiBJbnQpIC0m
Z3Q7IEludCB7Jm5ic3A74oCmIH08L2Rpdj48ZGl2Pjxicj48L2Rpdj48ZGl2PigxLi4uMTApLm1h
cChzcXVhcmUpICZuYnNwOy8vIHRvdGFsbHkgb2sgd2l0aCB0aGF0PC9kaXY+PGRpdj48YnI+PC9k
aXY+PGRpdj5jbGFzcyBTb21lQ2xhc3MgezwvZGl2PjxkaXY+Jm5ic3A7ICZuYnNwOyBmdW5jIGZv
byhfIHg6IEludCkgLSZndDsgSW50IHsg4oCmIH08L2Rpdj48ZGl2Pjxicj48L2Rpdj48ZGl2PiZu
YnNwOyAmbmJzcDsgZnVuYyBiYXIoKSB7PC9kaXY+PGRpdj4mbmJzcDsgJm5ic3A7ICZuYnNwOyAm
bmJzcDsgKDEuLi4xMCkubWFwKGZvbykgJm5ic3A7ICZuYnNwOyAmbmJ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