ARC-为什么对象指针在函数定义中需要显式的所有权类型? [英] ARC - why do object pointers require explicit ownership type in function definitions?

查看:77
本文介绍了ARC-为什么对象指针在函数定义中需要显式的所有权类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void testFunction (id testArgument[]) {
    return;
}

我收到错误消息必须明确描述对象数组参数的预期所有权".为什么ARC需要我在testArgument数组中指定对象的所有权类型?

I'm getting the error "Must explicitly describe intended ownership of an object array parameter". Why does ARC need me to specify the ownership type of the objects in the testArgument array?

推荐答案

为扩展Jeremy的答案,ARC在设计时有两个主要目标:

To expand on Jeremy's answer, ARC had two primary goals when designed:

  • 使纯Objective-C代码中的内存管理尽可能全自动,同时还能保持或最大化效率(实际上,ARC比手动保留释放更有效).

  • make memory management as fully automatic as possible in pure Objective-C code while also preserving or maximizing efficiency (in fact, ARC can be more efficient than manual retain release).

当跨越C和Objective-C之间的边界时,需要确切地声明内存管理意图.

require exactly specific declaration of memory management intent when crossing the boundary between C and Objective-C.

同样,ARC的实施也非常保守.也就是说,在传统上行为未定义的任何地方,ARC都会发出警告.

As well, the implementation of ARC is extremely conservative. That is, anywhere where the behavior has traditionally been "undefined", ARC will spew a warning.

因此,在这种情况下,需要声明意图,以便编译器可以将一致且特定的一组内存管理规则应用于数组的内容.

Thus, in this case, the declaration of intent is required so that the compiler can apply a consistent and specific set of memory management rules to the contents of the array.

这篇关于ARC-为什么对象指针在函数定义中需要显式的所有权类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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