[swift-users] Using #function causes big memory leak
Joe Groff
jgroff at apple.com
Mon Aug 28 10:36:27 CDT 2017
> On Aug 27, 2017, at 10:57 AM, Edward Connell via swift-users <swift-users at swift.org> wrote:
>
> I reported this about a year ago, but it has never been fixed and it seems like it should be fixed for the Swift 4.0 release.
What was the SR or radar number?
-Joe
>
> Here is a simple repro case. If you watch the memory monitor as it runs, you see memory consumption climb to 2.7GB when using #function, and no memory increase when using a static string.
>
> import Foundation
>
> class A {
> var counter = 0 {
> // didSet { onSet("counter") } // no leak
> didSet { onSet() } // huge leak
> }
>
> var properties = ["counter" : 0]
> func onSet(_ name: String = #function) {
> properties[name]! += 1
> }
> }
>
> var myclass = A()
>
> for i in 0..<10000000 {
> myclass.counter = i
> }
>
> print(myclass.properties["counter"]!)
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
More information about the swift-users
mailing list