Using ARC in tweaks: Difference between revisions

From iPhone Development Wiki
m (ARC isn't GC)
(fix description of ARC)
Line 3: Line 3:




ARC (or automatic reference counting), is a new method of memory management in Objective-C, first fully introduced in 2011 with iOS 5. ARC serves as an alternative to Objective-C's historic garbage collection model, in which memory is managed manually.
In Objective-C and Swift programming, Automatic Reference Counting (ARC) is a memory management enhancement where the burden of keeping track of an object's reference count is lifted from the programmer to the compiler. In traditional Objective-C, the programmer would send retain and release messages to objects in order to mark objects for deallocation or to prevent deallocation. Under ARC, the compiler does this automatically by examining the source code and then adding the retain and release messages in the compiled code.


While ARC can be very convenient, it can also be used as a crutch. ARC is a helpful tool while learning as one does not have to learn how to manage memory manually along with the rest of the language. However, it is important not to rely on it, and to still be capable of managing memory manually, as ARC will not be available in all scenarios.
While ARC can be very convenient, it can also be used as a crutch. ARC is a helpful tool while learning as one does not have to learn how to manage memory manually along with the rest of the language. However, it is important not to rely on it, and to still be capable of managing memory manually, as ARC will not be available in all scenarios.


== How should I use ARC in tweaks? ==
== How should I use ARC in tweaks? ==

Revision as of 11:45, 25 January 2015

What is ARC?

In Objective-C and Swift programming, Automatic Reference Counting (ARC) is a memory management enhancement where the burden of keeping track of an object's reference count is lifted from the programmer to the compiler. In traditional Objective-C, the programmer would send retain and release messages to objects in order to mark objects for deallocation or to prevent deallocation. Under ARC, the compiler does this automatically by examining the source code and then adding the retain and release messages in the compiled code.

While ARC can be very convenient, it can also be used as a crutch. ARC is a helpful tool while learning as one does not have to learn how to manage memory manually along with the rest of the language. However, it is important not to rely on it, and to still be capable of managing memory manually, as ARC will not be available in all scenarios.

How should I use ARC in tweaks?

As ARC was first introduced with iOS 5, it is very likely that iOS utilizes manual memory management (citation needed), as it seems unlikely that they would rewrite their entire codebase to support ARC. For this reason, it is not recommended that you use ARC in any hooks, as it could potentially cause problems -- injecting automatically managed-memory code into a manually memory-managed system simply doesn't sound like a good idea.

However, you probably will not encounter any problems using ARC in any custom classes that you create.