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
ARC differs from tracing garbage collection in that there is no background process that deallocates the objects asynchronously at runtime. Unlike tracing garbage collection, ARC does not handle reference cycles automatically.
Objective-C 2.0 adds garbage collection to the language as a replacement to the traditional retain / release reference counting scheme. Garbage collection is automatic object memory management.
Reference counting. Reference counting garbage collection is where each object has a count of the number of references to it. Garbage is identified by having a reference count of zero. An object's reference count is incremented when a reference to it is created, and decremented when a reference is destroyed.
Automatic Reference Counting (ARC) is a memory management option for Objective-C provided by the Clang compiler. When compiling Objective-C code with ARC enabled, the compiler will effectively retain, release, or autorelease where appropriate to ensure the object's lifetime extends through, at least, its last use.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With