View the reference count of an object under ARC, and the reference count of an arc object
 
 
The conclusions of various online articles and Q & A are "reference count values of objects cannot be printed under ARC ".
 
Indeed, ARC prohibits you from directly viewing the reference count of the Objective-C object, but can the Objective-C object still be converted to a Core Foundation object? So I started a small experiment:
 
Id obj = [[NSObject alloc] init]; printf ("retain count = % ld \ n", CFGetRetainCount (_ bridge CFTypeRef) (obj )));
 
Note that _ bridge is used for conversion. If _ bridge_retained is used for conversion, a Core Foundation object is generated, and retain the original Objective-C object, causing the reference count to be greater than the actual value.
 
Running result
 
 
 Retain count = 1
 
 
The project has enabled the ARC mode and correctly outputs the reference count value of the OC object.