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.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.
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.
When compared to manual memory management and garbage collection, ARC gives you the best of both worlds by cutting out the need to write retain / release code, yet not having the halting and sawtooth memory profiles seen in a garbage collected environment. About the only advantages garbage collection has over this are its ability to deal with retain cycles and the fact that atomic property assignments are inexpensive
Advantages of Garbage Collection
- GC can clean up entire object graphs, including retain cycles.
- GC happens in the background, so less memory management work is done as part of regular application flow.
Disadvantages of Garbage Collection
- Because GC happens in the background, the exact time frame for object releases is undetermined.
- When a GC happens, other threads in the application may be temporary put on hold.
Advantages of Automatic Reference Counting
- Real-time, deterministic destruction of objects as they become unused.
- No background processing, and more efficient on lower-power systems, such as mobile devices.
Disadvantages of Automatic Reference Counting
- Cannot cope with retain cycles.
0 comments:
Post a Comment