何时使用__bridge_transfer和__bridge [英] When to use __bridge_transfer and __bridge
问题描述
- 任何人都可以解释一下'__bridge_transfer'和'_ bridge'&什么时候使用' _bridge_transfer'和'__bridge'
- 我读过像ARC这样的交易,那么这两者的主要功能是什么
- Can any one explain me what is '__bridge_transfer' and '_bridge' & when to use '_bridge_transfer' and '__bridge'
- I read something like its deals with ARC, So what is the main function of these both
谢谢,
推荐答案
这些关键字用来告诉ARC系统如何处理你的非Objective-c指针。本质上,如果你使用__bridge,你告诉ARC不要处理转换指针的所有权,因为你将它从非Objective-c代码中释放出来,很可能是free()或CFRelease ...类型功能。另一方面,__ bridge_transfer将所有权转移到ARC,当对该对象的引用达到零时,ARC将通过标准释放机制释放您的objective-c(以及原始的非objective-c)对象。
These keywords are used to tell to ARC system how to handle your non-objective-c pointers. In essence, if you use __bridge, you are telling to ARC not to deal with the ownership of the converted pointer because you will free it from non-objective-c code, most likely with a free() or a CFRelease... type function. __bridge_transfer, on the other hand, transfers the ownership to ARC and ARC will free your objective-c (and thus also the original non-objective-c) object via the standard release mechanism when the references to that object hits zero.
这篇关于何时使用__bridge_transfer和__bridge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!