Dev:Using ARC in tweaks

What is ARC?
Quoting from the Wikipedia article on Automatic Reference Counting:

"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."

For hooks
Yes, use ARC. Writing hooks within a tweak are no different than using Objective-C methods to swizzle private APIs within an app. As such, in almost all cases it is totally fine to use ARC, and you should. However, there are rare cases where you might get unexpected behavior—such as not correctly marking autoreleasing parameters as autoreleasing, or forming a retain cycle, etc. This is not ARC's fault, and it is not unique to hooks. It really comes down to understanding how ARC works and what all the different keywords mean—but that is beyond the scope of this document.

For class declarations
Yes, use ARC.

Generally speaking
If you've had someone tell you shouldn't use ARC in tweaks, they are mistaken. Some developers still follow the misguided notion that ARC is unsafe for use in tweaks. Admittedly, some fault lies on this very wiki page for previously advising against ARC. Those people may consider it to be a bad idea to use it at all. Generally, you should just use ARC everywhere unless you have a specific reason not to. Without this approach, cases may arise where the programmer ends up forgetting which files use ARC and which files don't, inevitably leading to memory leaks. One example of this is when you write some code in a file that you thought uses ARC, but actually doesn't.

In a nutshell, just use ARC.

Using Theos
'''Recent versions of Theos will use ARC by default. The tweak file name will be Tweak.x instead of Tweak.xm with a necessary compiler flag added. You do not need to do anything further. '''

In your Makefile:

This applies ARC to all files you are compiling including your tweak file.

If you only want to use ARC on specific files, you can use one of two solutions. The most straightforward is to set the flag specifically for the file(s) in question:

For more complex situations, where a large amount of the code uses ARC, it may be beneficial to separate the projects. NewTerm, for instance, uses ARC but contains external code that isn't ARC. The latter code is split into a library called, which the main NewTerm project then links against:

You should pick another install path if your project isn't an app; try.

Without theos
This is how the flags would look like in a typical build process: