RELEASE_SAFELY 是什么意思,为什么它在 xcode4 中不起作用? [英] What does RELEASE_SAFELY mean and why does it not work in xcode4?

查看:53
本文介绍了RELEASE_SAFELY 是什么意思,为什么它在 xcode4 中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

RELEASE_SAFELYRELEASE_CF_SAFELY 是什么意思?好吧,它是为了释放对象,但为什么不使用 [obj release] ?

what does RELEASE_SAFELY or RELEASE_CF_SAFELY mean? Ok, it's for releasing objects but why not use [obj release]?

此外,我尝试在 xcode 4 中使用它,但遇到了错误:

Besides I tried to use it in xcode 4 but I am running into buid errors:

Undefined symbols for architecture i386:
  "_RELEASE_SAFELY", referenced from:
      -[AdressBookModel search:] in AdressBookModel.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

我可以只做 [obj release] 吗?你会考虑什么?

Can I do just [obj release] instead? What would you consider?

推荐答案

RELEASE_SAFELY 不是函数而是宏,通常是这样定义的:

RELEASE_SAFELY is not a function but a macro and is usually defined like this:

#define RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; }

(我认为它不是 SDK 的一部分,而是必须在每个项目中单独声明.我认为它与 XCode 版本没有任何关系.)

(I think it's not part of the SDK but has to be declared in each project separately. And I don't think it has anything to do with the XCode version.)

所以它首先调用release,然后另外将变量设置为nil.这是一种很好的做法,因为它可以防止重复释放或访问已释放的实例.

So it first calls release and then additionally sets the variable to nil. That's good practice because it prevents double releases or access to a deallocated instance.

您的代码似乎认为它是一个函数(而不是宏).可能编译器会警告您它尚未声明.

It seems that your code believes it's a function (instead of a macro). Probably the compiler warns you that it hasn't been declared.

解决方法是将上述宏定义放在适当的头文件中.

The fix is to put the above macro definition in an appropriate header file.

这篇关于RELEASE_SAFELY 是什么意思,为什么它在 xcode4 中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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