ope*_*rog 19 memory-management grand-central-dispatch ios automatic-ref-counting
我声明了一个属性来引用GCD队列:
@property (assign) dispatch_queue_t backgroundQueue;
Run Code Online (Sandbox Code Playgroud)
在类的init方法中,我创建了一个串行队列:
backgroundQueue = dispatch_queue_create("com.company.app", DISPATCH_QUEUE_SERIAL);
Run Code Online (Sandbox Code Playgroud)
ARC抱怨:"将保留对象分配给unsafe_unretained变量;对象将在分配后释放"
我必须使用__bridge_transfer吗?
在-dealloc我发布队列:
dispatch_release(backgroundQueue);
Run Code Online (Sandbox Code Playgroud)
ARC再次提出抱怨:"ARC禁止发布'发布'的明确消息"
我发现这令人困惑,因为这是一个C函数调用,思想队列是C对象,我必须自己处理内存管理!从什么时候开始为我处理C-objects?
Jan*_*ano 39
在iOS 6中,您可以cmd +单击dispatch_queue_t并查看:
/*
* By default, dispatch objects are declared as Objective-C types when building
* with an Objective-C compiler. This allows them to participate in ARC, in RR
* management by the Blocks runtime and in leaks checking by the static
* analyzer, and enables them to be added to Cocoa collections.
* See <os/object.h> for details.
*/
Run Code Online (Sandbox Code Playgroud)
因此,只需在属性中使用strong(除非在其他地方引用队列,并且您确实需要弱引用).
在iOS 6之前,您必须使用dispatch_retain和dispatch_release自行进行内存管理.在iOS 6中执行此操作将引发编译器错误.
| 归档时间: |
|
| 查看次数: |
13507 次 |
| 最近记录: |