ARC between Foundation and Core Foundation
来源:互联网 发布:域名为什么要买 编辑:程序博客网 时间:2024/05/20 08:22
A bridged cast is a C-style cast annotated with one of three keywords:
(__bridge T) op
casts the operand to the destination type T. If T is a retainable object pointer type, then op must have a non-retainable pointer type. If T is a non-retainable pointer type, then op must have a retainable object pointer type. Otherwise the cast is ill-formed. There is no transfer of ownership, and ARC inserts no retain operations.
(__bridge_retained T)
op casts the operand, which must have retainable object pointer type, to the destination type, which must be a non-retainable pointer type. ARC retains the value, subject to the usual optimizations on local values, and the recipient is responsible for balancing that +1.
(__bridge_transfer T)
op casts the operand, which must have non-retainable pointer type, to the destination type, which must be a retainable object pointer type. ARC will release the value at the end of the enclosing full-expression, subject to the usual optimizations on local values.
These casts are required in order to transfer objects in and out of ARC control; see the rationale in the section on conversion of retainable object pointers.
Using a __bridge_retained or __bridge_transfer cast purely to convince ARC to emit an unbalanced retain or release, respectively, is poor form.
Explain1:
(__bridge_transfer <NSType>) op
or alternativelyCFBridgingRelease(op)
is used to consume a retain-count of aCFTypeRef
while transferring it over to ARC. This could also be represented byid someObj = (__bridge <NSType>) op; CFRelease(op);
(__bridge_retained <CFType>) op
or alternativelyCFBridgingRetain(op)
is used to hand anNSObject
over to CF-land while giving it a +1 retain count. You should handle aCFTypeRef
you create this way the same as you would handle a result ofCFStringCreateCopy()
. This could also be represented byCFRetain((__bridge CFType)op); CFTypeRef someTypeRef = (__bridge CFType)op;
__bridge
just casts between pointer-land and Objective-C object-land. If you have no inclination to use the conversions above, use this one.
Explain2:
__bridge
transfers a pointer between Objective-C and Core Foundation with no transfer of ownership.__bridge_retained
casts an Objective-C pointer to a Core Foundation pointer and also transfers ownership to you.You are responsible for calling CFRelease or a related function to relinquish ownership of the object.
__bridge_transfer
moves a non-Objective-C pointer to Objective-C and also transfers ownership to ARC.ARC is responsible for relinquishing ownership of the object.
- ARC between Foundation and Core Foundation
- cast between Objective-C and Core Foundation-style objects
- 当Core Foundation遇上ARC
- Core Foundation 与 foundation
- Core Foundation与Foundation
- Core Foundation
- core foundation create and get Rule
- ios-Foundation和Core Foundation
- Core Foundation 对象不属于ARC的管辖范围
- Core Foundation 框架
- Core Foundation 框架
- Core Foundation内存管理
- Core Foundation 框架
- Core Foundation 框架
- Core Foundation 框架【转】
- Core Foundation框架
- Core Foundation 框架
- Core Foundation框架
- 双向链表
- sublime text 2 对js进行重新排版。
- Oracle - expdp、impdp导入从原表空间更换到其他表空间 ----导入到另个表空间测试
- Oracle数据字典和动态视图小结
- mysql has gone away
- ARC between Foundation and Core Foundation
- 【Z-Stack发送函数AF_DataRequest】
- Android 开发利用wifi调试简介
- B - Sort the Array
- Weblogic10.3.5 数据库连接问题
- cassandra 批量插入
- Hibernate 连接查询
- 实现触摸的类的继承方法有2种
- 从本地上传整个文件夹到hdfs的java程序