ARC之后,我应该为调度队列使用什么属性? [英] What property should I use for a Dispatch Queue after ARC?

查看:51
本文介绍了ARC之后,我应该为调度队列使用什么属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用视图控制器将调度队列作为属性维护.我在视图控制器的init方法中创建了此队列一次,并对某些后台任务重用了几次.在ARC之前,我是这样做的:

I maintain a dispatch queue as a property with my view controller. I create this queue once in my view controller's init method, and reuse a few times for some background tasks. Before ARC, I was doing this:

@property (nonatomic, assign) dispatch_queue_t filterMainQueue;

在初始化中:

if (filterMainQueue == nil) {
     filterMainQueue = dispatch_queue_create("com.myQueue.CJFilterMainQueue", NULL);
}

但是在ARC之后,我不确定是应该还是分配",还是应该是强"或弱". ARC转换器脚本没有进行任何更改,但是我不确定是否由于使用此队列而可能释放该队列的事实而引起了细微的错误?

But after ARC, I'm not sure if this should still be "assign", or should it be "strong" or "weak". The ARC convertor script didn't change anything but I'm not sure if a subtle bug is coming from the fact that this queue might be deallocated while it's being used?

使用ARC时,这三种类型的属性之间有什么区别,什么对调度队列最有效?

What would be the difference between the 3 types of properties, and what will work the best for a dispatch queue, when using ARC?

推荐答案

更新后的答案:

在当前的OS X和iOS中,ARC现在将Dispatch对象视为Obj-C对象.它们将以与Obj-C对象相同的方式进行内存管理,并且您应该对属性使用strong.

In current OS X and iOS, Dispatch objects are now treated as Obj-C objects by ARC. They will be memory-managed the same way that Obj-C objects will, and you should use strong for your property.

这由<os/object.h>中定义的OS_OBJECT_USE_OBJC宏控制.当您的部署目标是OS X 10.8或更高版本或iOS 6.0或更高版本时,默认情况下将其设置为1.如果要部署到较旧的操作系统,则该位置留在0,您应该在下面看到我的原始答案.

This is controlled by the OS_OBJECT_USE_OBJC macro, defined in <os/object.h>. It's set to 1 by default when your deployment target is OS X 10.8 or higher, or iOS 6.0 or higher. If you're deploying to an older OS, then this is left at 0 and you should see my original answer below.

原始答案:

调度对象(包括队列)不是Obj-C对象,因此唯一的选择是assign.如果尝试使用strongweak,则编译器将引发错误. ARC对GCD没有影响.

Dispatch objects (including queues) are not Obj-C objects, so the only possible choice is assign. The compiler will throw an error if you try to use strong or weak. ARC has no impact on GCD.

这篇关于ARC之后,我应该为调度队列使用什么属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆