> On 25. Oct 2017, at 13:41, David Hart via swift-evolution > <[email protected]> wrote: > > I got bit again by a sneaky memory leak concerning local functions and would > like to discuss a small language change. I vaguely remember this being > discussed in the past, but can’t find the thread (if anybody could point me > to it, I’d appreciate it). Basically, here’s an example of the leak: > > class A { > func foo() { > func local() { > bar() > } > > methodWithEscapingClosure { [unowned self] _ in > self.bar() > local() // this leaks because local captures self > } > } > > func bar() { > } > } > > Its sneaky because local’s capturing of self is not obvious if you’ve trained > your brain to watch out for calls prefixed with self. I would suggest having > the compiler force users to make self capturing explicit, the same way it > does for closures: > > class A { > func foo() { > func local() { > bar() // error: Call to method ‘bar' in function ‘local' requires > explicit 'self.' to make capture semantics explicit > } > > // ... > } > } > > What do you think? > > David. > > _______________________________________________ > swift-evolution mailing list > [email protected] > https://lists.swift.org/mailman/listinfo/swift-evolution
Yes, this issue (and variants of it) have come up lots of times (https://www.google.de/search?q=nested+function+noescape+site:lists.swift.org <https://www.google.de/search?q=nested+function+noescape+site:lists.swift.org>) There’s also SR-2274 (https://bugs.swift.org/browse/SR-2274 <https://bugs.swift.org/browse/SR-2274>) Personally, I consider it a bug and definitely support fixing it. - Karl
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
