Swift Code
override func viewDidLoad() {
super.viewDidLoad()
var v1 = ViewController()
let v2 = ViewController2()
print("\(CFGetRetainCount(v1)) and \(CFGetRetainCount(v2))")
}
In Swift reference count printing as 2 and 2
Objective C Code
- (void)viewDidLoad {
[super viewDidLoad];
ViewController *v1 = [[ViewController alloc]init];
ViewController2 *v2 = [[ViewController2 alloc]init];
NSLog(@"%ld and %ld",CFGetRetainCount((__bridge CFTypeRef)(v1)),CFGetRetainCount((__bridge CFTypeRef)(v2)));
}
In Objective C reference count printing as 1 and 1
Why reference counts are different in objective c and swift ?