我应该在objective-c中使用ARC吗?

时间:2023-01-18 19:54:39

Looking at the release notes of OS 10.7, there's some stuff about using Automatic Reference counting (ARC) to make memory management simple. I'm about to embark on a new Cocoa project soon and wondered whether it would be worth using the model (the way I understand it, you can't mix between using ARC and not using it)?

查看OS 10.7的发行说明,有一些关于使用自动引用计数(ARC)来简化内存管理的内容。我即将开始一个新的Cocoa项目,并想知道是否值得使用该模型(我理解它的方式,你不能在使用ARC和不使用它之间混合)?

The dilemma seems to be using something new versus using something that could potentially save lots of debugging time later. But is that the case? Has anyone played around with it and found no real-world benefit?

这种困境似乎是使用新的东西而不是使用可能在以后节省大量调试时间的东西。那是这样的吗?有没有人玩过它,发现没有现实世界的好处?

2 个解决方案

#1


14  

Without a doubt you should use ARC. ARC injects the retain release calls at the most appropriate times, so you may actually see lower average memory use than you would if you didn't use ARC.

毫无疑问,你应该使用ARC。 ARC会在最合适的时间注入保留释放调用,因此您实际上可能会看到比不使用ARC时更低的平均内存使用量。

I have used ARC and it is immensely powerful. You stop having random crashes and your app just feels more responsive. As they said at WWDC, there is no reason not to use Automatic Reference Counting.

我使用过ARC,它非常强大。你停止随机崩溃,你的应用程序只是感觉更敏感。正如他们在WWDC上所说,没有理由不使用自动参考计数。

Also, you can use non-ARC files in the same project as ARC files.

此外,您可以在与ARC文件相同的项目中使用非ARC文件。

#2


5  

I agree with FreeAsInBeer about using ARC. However, it should also be made clear that garbage collection (GC) should not be used. It looks like Apple is henceforth going to focus their efforts ARC, while letting GC die a slow death. This is wonderful because ARC is clearly a far superior technology, whereas GC is slow and extremly buggy.

我同意FreeAsInBeer关于使用ARC的观点。但是,还应该明确不应使用垃圾收集(GC)。看起来苹果今后将集中精力ARC,同时让GC慢慢死亡。这很棒,因为ARC显然是一种非常优越的技术,而GC则是缓慢而极端的错误。

So yes. Use ARC. Stay away from GC.

是的。使用ARC。远离GC。

#1


14  

Without a doubt you should use ARC. ARC injects the retain release calls at the most appropriate times, so you may actually see lower average memory use than you would if you didn't use ARC.

毫无疑问,你应该使用ARC。 ARC会在最合适的时间注入保留释放调用,因此您实际上可能会看到比不使用ARC时更低的平均内存使用量。

I have used ARC and it is immensely powerful. You stop having random crashes and your app just feels more responsive. As they said at WWDC, there is no reason not to use Automatic Reference Counting.

我使用过ARC,它非常强大。你停止随机崩溃,你的应用程序只是感觉更敏感。正如他们在WWDC上所说,没有理由不使用自动参考计数。

Also, you can use non-ARC files in the same project as ARC files.

此外,您可以在与ARC文件相同的项目中使用非ARC文件。

#2


5  

I agree with FreeAsInBeer about using ARC. However, it should also be made clear that garbage collection (GC) should not be used. It looks like Apple is henceforth going to focus their efforts ARC, while letting GC die a slow death. This is wonderful because ARC is clearly a far superior technology, whereas GC is slow and extremly buggy.

我同意FreeAsInBeer关于使用ARC的观点。但是,还应该明确不应使用垃圾收集(GC)。看起来苹果今后将集中精力ARC,同时让GC慢慢死亡。这很棒,因为ARC显然是一种非常优越的技术,而GC则是缓慢而极端的错误。

So yes. Use ARC. Stay away from GC.

是的。使用ARC。远离GC。