id obj = [[NSObject alloc] init];
CFTypeRef ref = (__bridge_retained CFTypeRef) obj;
NSLog(@"CF Retain Count %ld", CFGetRetainCount(ref)); //Q1
CFRetain(ref);
id obj2 = (__bridge_transfer id)ref;
ref = (__bridge_retained CFTypeRef)obj2;
NSLog(@"CF Retain Count %ld", CFGetRetainCount(ref)); //Q2
id obj3 = obj;
NSLog(@"CF Retain Count %ld", CFGetRetainCount(ref)); //Q3
id obj4 = (__bridge id)ref;
NSLog(@"CF Retain Count %ld", CFGetRetainCount(ref)); //Q4
//Q5 : How many CFRelease/CFBridgingRelease do we need here to release the object when it goes out of scope?
If you can't answer those, my hint is, there is indeed only 1 reference count in ObjC, whether
you use the bridged cast or not.See the cheat sheet below:
__bridge_retained = CFBridgingRetain = CFRetain + casting
__bridge_transfer = CFBridgingRelease = CFRelease + casting
__bridge : Does nothing other than casting