7

Just wondering if anyone knows what is the different between Objective C 2.0 Garbage Collector and new Automatic Reference Counter in IOS 5 SDK ?

is IOS 5 SDK also use Objective C 2.0 ?

note : what I mean objective C 2.0 - I saw from this link http://theocacao.com/document.page/510

Thanks

James Webster
  • 31,873
  • 11
  • 70
  • 114
kkurni
  • 1,371
  • 1
  • 13
  • 11
  • 4
    Apple’s Objective-C garbage collector is not available on iOS. It’s for Mac OS X only. –  Oct 26 '11 at 08:12
  • possible duplicate of [What is the difference between Objective-C automatic reference counting and garbage collection?](http://stackoverflow.com/questions/7874342/what-is-the-difference-between-objective-c-automatic-reference-counting-and-garb) – Brad Larson Oct 26 '11 at 21:41

2 Answers2

13

Just wondering if anyone knows what is the different between Objective C 2.0 Garbage Collector and new Automatic Reference Counter in IOS 5 SDK ?

ARC is not a Garbage Collector. It is better to think of it as manual reference counting (retain/release/autorelease) calls which are added by the compiler. It also uses some runtime tricks.

If you are completely new to ObjC on Apple systems: All of Apple's Objective-C types use reference counting, but there are multiple variants now. Before ARC, and before GC, all we used was manual reference counting (MRC). With MRC, you would explicitly retain and release your objects. MRC was difficult for some people, particularly those who had spent little time managing their memory explicitly. Therefore, the demand for simpler systems grew over time. MRC programs also require that you write a good amount of memory management code, which can become tedious.

See Brad's excellent answer here for some more details.

is IOS 5 SDK also use Objective C 2.0?

Yes, but the ObjC Garbage Collector is not and was never an option on iOS.

Community
  • 1
  • 1
justin
  • 104,054
  • 14
  • 179
  • 226
8

NB: Garbage collection isn't available on iOS but according to my comments, ARC is available on Mac OSX 10.6+. The differences are still comparable however.

With automatic reference counting, objects are still deallocated as soon as they go out of scope.

With garbage collection, objects can remain in memory until the garbage collector does its next sweep and finds objects which no longer have references.

James Webster
  • 31,873
  • 11
  • 70
  • 114