IOS 8: "Turn" corefoundation and nsobject transitions under ARC

Source: Internet
Author: User

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.

    • __bridgeRepresents 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_transferIndicates that the reference count administrator of the CF object is transferred to NSObject, which is managed by ARC, without any further CFRelease() release.
    • __bridge_retainedIndicates 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.