Source Address: http://fann.im/blog/2013/12/25/corefoundation-bridge-nsobject/
Corefoundation has its own reference counting processing method, under CF if the method of generating the object has create, retain, copy means that CF will add one to the reference count in its own way, which needs to be released at the end CFRelease()
. ARC currently only has an automatic reference count processing for NSObject objects, so the __bridge
__bridge_transfer
__bridge_retained
conversion of reference count management is required in arc if there are corefoundation objects and NSObject object conversions.
__bridge
Represents a reference count balance for CF objects and nsobject, without the need to convert administrative rights. Suitable for converting CF objects obtained with a method that does not contain create, retain, copy to NSObject.
__bridge_transfer
Indicates that the reference count administrator of the CF object is transferred to NSObject, which is managed by ARC, without any further CFRelease()
release.
__bridge_retained
Indicates that the reference count management of the NSObject object is transferred to CF management, and the reference count is added one, then the object needs to be disposed at the CF layer CFRelease()
.
The SDK has two macros CFBridgingRetain
that CFBridgingRelease
can be used directly, to be aware of the CFBridgingRetain
CFRelease()
release.
After using a cfbridgingretain in an nsobject, the caller must take responsibility for calling Cfrelease at an APPROPRI Ate time.ns_inline cf_returns_retained cftyperef Cfbridgingretain (id x) {return (__bridge_retained cftyperef) span class= "n" >x;} ns_inline id cfbridgingrelease ( cftyperef cf_consumed x) {return (__bridge_transfer id) x;}
Refer to Arc engineering conversion and development considerations
IOS 8: "Turn" corefoundation and nsobject transitions under ARC