Automatic Reference Counting (ARC) is a compiler feature that provides automatic memory management of Objective-C objects.
520
votes
5answers
112k views
How can I disable ARC for a single file in a project?
I am using ARC successfully in my project. However, I have encountered a few files (e.g., in unit tests and mock objects) where the rules of ARC are a little more fragile right now. I recall hearing ...
313
votes
13answers
43k views
performSelector may cause a leak because its selector is unknown
I'm getting the following warning by the ARC compiler:
"performSelector may cause a leak because its selector is unknown".
Here's what I'm doing:
[_controller ...
169
votes
4answers
26k views
Should IBOutlets be strong or weak under ARC?
I am developing exclusively for iOS 5 using ARC. Should IBOutlets to UIViews (and subclasses) be strong or weak?
The following:
@property (nonatomic, weak) IBOutlet UIButton *button;
Would get rid ...
138
votes
4answers
19k views
What kind of leaks does automatic reference counting in Objective-C not prevent or minimize?
In the Mac and iOS platforms, memory leaks are often caused by unreleased pointers. Traditionally, it has always been of utmost importance to check your allocs, copies and retains to make sure each ...
125
votes
5answers
50k views
Some questions about Automatic Reference Counting in iOS5 SDK
I'm currently developing an app for iPad. The development started for iOS 4.2 and is now continuing (and I think will be completed) for iOS 4.3.
I just read about ARC in iOS 5, and basically I ...
121
votes
4answers
27k views
Disable Automatic Reference Counting for Some Files
I have downloaded the iOS 5 SDK and found that ARC is a great feature of the new Apple compiler. For the time being, many third party frameworks don't support ARC. Could I use ARC for my new code and ...
118
votes
4answers
28k views
How does the new automatic reference counting mechanism work?
Can someone briefly explain to me how ARC works? I know it's different from Garbage Collection, but I was just wondering exactly how it worked.
Also, if ARC does what GC does without hindering ...
97
votes
6answers
53k views
iOS 5 Best Practice (Release/retain?)
As a beginning iPhone programmer, what is the best practice for writing apps to be used either with iOS 5 or older versions? Specifically, should I continue using the release/retain of data, or should ...
90
votes
3answers
21k views
How do I avoid capturing self in blocks when implementing an API?
I have a working app and I'm working on converting it to ARC in Xcode 4.2. One of the pre-check warnings involves capturing self strongly in a block leading to a retain cycle. I've made a simple code ...
88
votes
2answers
17k views
Can I use Objective-C blocks as properties?
Is it possible to have blocks as properties using the standard property syntax?
Are there any changes for ARC?
80
votes
2answers
28k views
ARC and bridged cast
With ARC, I can no longer cast CGColorRef to id. I learned that I need to do a bridged cast. According clang docs:
A bridged cast is a C-style cast annotated with one of three keywords:
...
80
votes
3answers
27k views
Objective-C ARC: strong vs retain and weak vs assign
There are two new memory management attributes for properties introduced by ARC, strong and weak.
Apart from copy, which is obviously something completely different, are there any differences between ...
78
votes
1answer
22k views
What does “Receiver type 'CALayer' for instance message is a forward declaration” mean here?
I'm porting a block of code from an iOS4 project to iOS5 and I'm having some troubles with ARC. The code generates a PDF from a screen capture.
PDF Generation Code
UIView *captureView;
...
...
76
votes
1answer
20k views
Custom dealloc using ARC (Objective-C)
I have a short question about ARC and releasing objects.
In my little iPad App I have a "switch language" functionality realized with an observer. Every ViewController is registrating it self at my ...
75
votes
3answers
10k views
Why does Apple recommend to use dispatch_once for implementing the singleton pattern under ARC?
What's the exact reason for using dispatch_once in the shared instance accessor of a singleton under ARC?
+ (MyClass *)sharedInstance
{
// Static local predicate must be initialized to 0
...