假设一个测试场景
Employee *aObj = [[Employee alloc]init];
NSLog(@"Retain count is1: %ld", CFGetRetainCount((__bridge CFTypeRef)aObj));
Employee *bObj = aObj;
NSLog(@"Retain count is2: %ld", CFGetRetainCount((__bridgCFTypeRef)bObj));
Employee *cObj = bObj;
NSLog(@"Retain count is3: %ld", CFGetRetainCount((__bridge CFTypeRef)cObj));
Then output is :
TestMemory[1949:62438] Retain count is1: 1
TestMemory[1949:62438] Retain count is2: 2
TestMemory[1949:62438] Retain count is3: 3
Employee *aObj = [[Employee alloc]init];
Employee *bObj = aObj;
Employee *cObj = bObj;
NSLog(@"Retain count is1: %ld", CFGetRetainCount((__bridge CFTypeRef)aObj));
NSLog(@"Retain count is2: %ld", CFGetRetainCount((__bridge CFTypeRef)bObj));
NSLog(@"Retain count is3: %ld", CFGetRetainCount((__bridge CFTypeRef)cObj));
Then output is :
TestMemory[1949:62438] Retain count is1: 3
TestMemory[1949:62438] Retain count is2: 3
TestMemory[1949:62438] Retain count is3: 3
所以我得到两个不同的输出,使用相同的代码。谁能解释为什么会这样?请帮助我。