Implementing __autoreleasing ownership qualifier
来源:互联网 发布:最高效判断质数的算法 编辑:程序博客网 时间:2024/05/17 23:21
__autoreleasing ownership qualifier
Assigning an object to any variables qualified with __autoreleasing is equivalent to calling the autorelease method in a non-ARC environment. Let’s see how it works with source code.
@autoreleasepool {
id __autoreleasing obj = [[NSObject alloc] init];
}
It adds an object of NSObject class to the autorelease pool. Let’s see how the compiler translates it.
/* pseudo code by the compiler */
id pool = objc_autoreleasePoolPush();
id obj = objc_msgSend(NSObject, @selector(alloc));
objc_msgSend(obj, @selector(init));
objc_autorelease(obj);
objc_autoreleasePoolPop(pool);
It just works as I explained with Apple’s implementation. (See Chapter 1, Section “Apple’s Implementation of autorelease.”) The autorelease mechanism itself works exactly same as in a non-ARC environment although the source codes are different.
What happens if the object is not obtained by the alloc/new/copy/mutableCopy method group? Let’s see the next example with NSMutableArray class method “array”.
@autoreleasepool {
id __autoreleasing obj = [NSMutableArray array];
}
Let’s check what is different from the previous example.
/* pseudo code by the compiler */
id pool = objc_autoreleasePoolPush();
id obj = objc_msgSend(NSMutableArray, @selector(array));
objc_retainAutoreleasedReturnValue(obj);
objc_autorelease(obj);
objc_autoreleasePoolPop(pool);
Although, objc_retainAutoreleasedReturnValue is used, other autorelease pool-related codes are exactly the same as the previous example.
- Implementing __autoreleasing ownership qualifier
- Implementing __strong ownership qualifier
- Implementing __weak ownership qualifier
- __unsafe_unretained ownership qualifier
- Ownership
- Ownership
- @Qualifier
- Take ownership
- __autoreleasing 修饰符
- __autoreleasing 修饰符
- ARC中__autoreleasing
- ios-__autoreleasing修饰符
- io strong,weak ,__unsafe_unretained, __autoreleasing
- Processes/Workflow ownership FAQs
- Ownership of Memory Management
- ownership的觉醒
- Ownership of Container Object
- Spring @Qualifier
- Set Matrix Zeroes
- JS文件默认编码方式及修改
- hibernate手动分配assigned 主键增长方式
- C++ Primer 5 笔记 第一章 开始
- Java排序之冒泡法
- Implementing __autoreleasing ownership qualifier
- ALSA 用户空间之 TinyAlsa
- 明珠的底气,雷军的胆气,马云的地气--ZenNew禅芯
- Future和FutureTask(多线程)
- Java排序之选择排序
- 特征向量的物理意义&几何含义
- poj1265 in e area
- DES 算法的 C++ 与 JAVA 互相加解密
- linux-时间子系统