问题描述
根据 Apple的ARC文档,使用ARC时,人们对软件开发方式的重大改变.
According to Apple's ARC Documentation, there are a fairly significant number of changes to the way that one develops software when using ARC.
作为Objective-C的完整入门者,最好是禁用ARC,然后让我对幕后发生的事情有一个更好的底层了解,这是个好主意吗?还是ARC本质上不赞成使用旧方法",以至于花时间学习真的不值得?
As a complete beginner to Objective-C, would it be better to start off with ARC disabled, with the idea that it would give me a better low-level understanding of what is going on behind the scenes? Or has ARC essentially deprecated the 'old way' of doing things, to the point that it's not really worth spending time learning?
推荐答案
这基本上是一个意见问题,因此非常危险.
This is basically an opinion question, and is therefore fairly dangerous.
我的意见是肯定的.值得学习基本的内存管理.资格没有陷入困境.通过一些非常简单的项目,了解ARC在幕后为您做什么.一旦您对如何处理内存管理有了基本的了解,即如何避免保留周期(因为引用它们的子句仍然是ARC的问题).一旦您对内存管理有了基本的了解.开始使用ARC.
My Opinion is a qualified yes. It is worth learning basic memory management. The qualification being don't get bogged down in it. Learn what ARC is doing for you under the hood with some very simple projects. Once you have a basic understanding of how to handle memory management, i.e. how to avoid retain cycles(as jemmons alluded to they can still be a problem with ARC).Once you have a basic grasp of memory management. Start using ARC.
正如Jason Coco指出的那样,ARC处理(简单地说)NSObject子类的内存管理.因此,如果需要使用所有CF对象,您仍将自己处理.
Also as Jason Coco pointed out ARC handles memory management for (to put it simply) NSObject subclasses. So all of the CF Objects you will still be handling yourself, if you need to use them.
在WWDC2011会议323-引入自动引用计数中,可以找到有关ARC在幕后为您做的很好的解释.
An excellent explanation about what ARC is doing for you under the hood can be found in the WWDC2011 Session 323 - Introducing Automatic Reference Counting.
但是还有其他一些因素可能会影响您的决定.
But there are some other considerations that might steer your decision.
您需要定位哪些设备?
如果您打算面向iOS 4.3及更高版本,ARC将为您有效地处理(NSObject子类的)内存管理.
If you plan to target iOS 4.3 and up ARC effectively handles memory management for you.(of NSObject subclasses)
如果计划以iOS 4.2为目标,则将无法使用weak
引用(将使用unsafe_unretained). iPhone 3g? & iPod touch第二代仍停留在此OS级别,因为仍有许多此类设备仍在使用中,许多开发人员仍将其作为目标.
If you plan to target iOS 4.2 then you will not be able to use weak
references(you will use unsafe_unretained). iPhone 3g? & iPod touch 2nd gen are stuck at this OS level, because there are many of these devices still in service many developers are still targeting them.
如果您计划将iOS
定位为早于4.2(这很少见),则肯定需要学习MRC(手动参考计数).
If you plan to target iOS
s earlier than 4.2(This would be rare) you will definitely need to learn MRC(Manual Reference Counting).
如果您打算构建Mac Apps,则该平台上有一个垃圾收集器. ARC也是一种选择(完整的ARC 10.7,没有弱支持10.6).
If you plan to build Mac Apps, there is a garbage collector available on that platform. ARC is also an option(full ARC 10.7, no weak support 10.6).
这篇关于从Objective-C开始:是ARC还是不ARC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!