This rabbit hole is way bigger, but, in the mean time, I have two questions:
- Why is the
deinit
code never called here? - Why is the retain count returned: 2?
Code is below and compiled in macOS Big Sur with the latest everything as of now.
import Foundation
class Person {
let name: String
init(name: String) {
self.name = name
print("\(name) is being initialized")
}
deinit {
print("\(name) is being deinitialized")
}
}
let a = Person(name: "Jessica Doe")
print("CFGetRetainCount(a): \(CFGetRetainCount(a))")
Compiled with: swiftc /tmp/main.swift -o /tmp/main
.
Output is:
Jessica Doe is being initialized
CFGetRetainCount(a): 2
Why in God's name is the code for the deinit
not called here?
Second, it might be that CFGetRetainCount
is dumb and print two just because it doesn't like 1, or whatever, but it doesn't say anything in the documentation about why it would print 2. It'd be super fun if CFGetRetainCount
was increasing the count from 1 to 2 by grabbing a strong reference to it, but that would explain the behavior.