Avatar
クロージャの呼び出しを変えると結果が変わる例 @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 }