Inconsistent reference counting of UnsafeMutablePointer

FWIW, I got

isKnownUniquelyReferenced: true
deinitialize
deinit
deallocate
end

for both variations*.


Note that isKnownUniquelyReferenced is allowed false negative (the reference is unique, but not known to be so). That said, this example should be simple enough for the compiler not to play that card.


It's somewhat off-topic, but there's also a recent effort to shift the lifetime of a variable from the last usage to the end of its scope. That doesn't apply here, but it might be helpful if you're dealing with precise deinit invocation.


* Compiled using
swift-driver version: 1.26.21
Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)
Target: x86_64-apple-macosx12.0

1 Like