关于 Xcode 4.3 中的自动发布
嗨,我是目标 C 的新手。 在旧版本的 Xcode 中,当我们创建新项目时,IDE 会生成如下所示的 NSAutoreleasePool 对象,以允许自动释放对象
int main (int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
[pool drain];
return 0; }
。但是在 Xcode 4.3 中,IDE 会生成以下代码
int main (int argc, const char * argv[])
{
@autoreleasepool {
//insert code
}
return 0;
}
。在旧版本中,我可以手动释放对象。 。使用新的 Xcode 4.3,当我尝试释放对象但释放功能被划掉时......为什么......?
谢谢。
Hi I'm new to objective C.
In the old version of Xcode, when we create new project the IDE generate NSAutoreleasePool object like below to allow auto release an object
int main (int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
[pool drain];
return 0; }
However in the Xcode 4.3, the IDE generate the below code
int main (int argc, const char * argv[])
{
@autoreleasepool {
//insert code
}
return 0;
}
With the older version .. i could manually release the object .. With the new Xcode 4.3 when i tried release the object but the release function is crossed out ... Why is that...?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
新项目默认启用 ARC(自动引用计数)。在 ARC 中,禁止对 objc 对象进行引用计数操作。
新项目序列中应该有一个选项来使用手动引用计数或 GC。
New projects have ARC (Automatic Reference Counting) enabled by default. In ARC, reference count operations on objc objects are forbidden.
There should be an option in the New Project sequence to use manual reference counting or GC.
您的项目中启用了 ARC(自动引用计数)。在 ARC 中,不允许对对象进行引用计数操作(例如释放)。通过“release”的红线仅表示该方法已被弃用或不再需要。系统会为你释放一切。
ARC (Automatic Reference Counting) is enables in your project. In ARC, reference count operations (ex. release) on objects are not allowed. The red line through "release" simply means that the method is deprecated, or no longer needed. The system will release everything for you.