Avatar
Avatar
yimajo
クロージャの呼び出しを変えると結果が変わる例 @swift-5.5.3 let foo = Foo() print("init Foo: refCount = \(_getRetainCount(foo))") do { var closure: (() -> ())? = { [bar = foo] in print("in closure: refCount = \(_getRetainCount(bar))") } print("before closure(): refCount = \(_getRetainCount(foo))") closure!() print("after closure?(): refCount = \(_getRetainCount(foo))") closure!() print("after closure?(): refCount = \(_getRetainCount(foo))") closure = nil }
exit status: 1 with stderr:<stdin>:1:11: error: cannot find 'Foo' in scope let foo = Foo() ^~~