[Objective-C] _ bridge ,__ meaning of bridge_retained and _ bridge_transfer, difference and use

Source: Internet
Author: User

Using Arc can help us reduce a lot of memory management burden, especially when we use JavaProgramPersonnel. However, I am not a strong Java Foundation. After two years of development, IOS has become accustomed to manual memory management, and arc is often used to hitting the wall.

Recently we encountered the problem of cfobject and nsobject conversion. Because arc cannot manage the lifecycle of core Foundation objects, we need to use _ bridge between core Foundation and arc, __bridge_retained and _ bridge_transfer conversion keywords.

According to Apple's official documentation (https://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html ):

_ Bridge only performs type conversion, but does not modify the object (memory) management right;

_ Bridge_retained (you can also use cfbridgingretain) to convert an objective-C object to a core Foundation object, and assign the object (memory) management right to us, cfrelease or related methods will be used to release objects in the future;

_ Bridge_transfer (cfbridgingrelease can also be used) converts the core foundation object to an objective-C object, and grants the object (memory) Management Right to arc.

Related Article

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.