Questions tagged [automatic-ref-counting]

Automatic Reference Counting (ARC) is a compiler feature that provides automatic memory management of Objective-C and Swift objects.

Automatic Reference Counting (ARC) is a technology introduced in LLVM 3.0 (which ships with Xcode 4.2) for managing memory in Objective-C. Swift also uses ARC. This method removes the need for much of the code previously required for manual memory management (MRR) of objects in Objective-C (such as manually calling release) and introduces new memory management qualifiers (namely strong and weak). ARC is a compile-time feature that transparently incorporates the appropriate reference-counting memory management calls into the final application. Like manual reference counting, there is no run-time garbage collection.

References:

See Also

  • For the Arc programming language, see arc-lisp.
3809 questions
221
votes
7 answers

capturing self strongly in this block is likely to lead to a retain cycle

How can I avoid this warning in xcode. Here is the code snippet: [player(AVPlayer object) addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(0.1, 100) queue:nil usingBlock:^(CMTime time) { current+=1; if(current==60) { …
211
votes
1 answer

Custom dealloc and ARC (Objective-C)

In my little iPad app I have a "switch language" function that uses an observer. Every view controller registers itself with my observer during its viewDidLoad:. - (void)viewDidLoad { [super viewDidLoad]; [observer…
Niku
  • 2,219
  • 2
  • 14
  • 4
211
votes
6 answers

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 performance, then why does Java use GC? Why doesn't it…
205
votes
8 answers

Why is @autoreleasepool still needed with ARC?

For the most part with ARC (Automatic Reference Counting), we don't need to think about memory management at all with Objective-C objects. It is not permitted to create NSAutoreleasePools anymore, however there is a new syntax: @autoreleasepool { …
mk12
  • 25,873
  • 32
  • 98
  • 137
183
votes
4 answers

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 keep the current retain/release code unchanged?…
nonamelive
  • 6,510
  • 8
  • 40
  • 47
178
votes
10 answers

How do I implement an Objective-C singleton that is compatible with ARC?

How do I convert (or create) a singleton class that compiles and behaves correctly when using automatic reference counting (ARC) in Xcode 4.2?
cescofry
  • 3,706
  • 3
  • 26
  • 22
170
votes
3 answers

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: (__bridge T) op casts the operand to the destination type T.…
Morrowless
  • 6,856
  • 11
  • 51
  • 81
144
votes
7 answers

Fix warning "Capturing [an object] strongly in this block is likely to lead to a retain cycle" in ARC-enabled code

In ARC enabled code, how to fix a warning about a potential retain cycle, when using a block-based API? The warning: Capturing 'request' strongly in this block is likely to lead to a retain cycle produced by this snippet of code: ASIHTTPRequest…
Guillaume
  • 21,685
  • 6
  • 63
  • 95
135
votes
5 answers

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 understood that we will never need to release and retain…
Luke47
  • 1,583
  • 3
  • 11
  • 14
126
votes
4 answers

In which situations do we need to write the __autoreleasing ownership qualifier under ARC?

I'm trying to complete the puzzle. __strong is the default for all Objective-C retainable object pointers like NSObject, NSString, etc.. It's a strong reference. ARC balances it with a -release at the end of the scope. __unsafe_unretained equals the…
Proud Member
  • 40,078
  • 47
  • 146
  • 231
126
votes
2 answers

Do I set properties to nil in dealloc when using ARC?

I am trying to learn Automatic Reference Counting in iOS 5. Now the first part of this question should be easy: Is it correct that I do NOT need to write explicit release-property statements in my dealloc when using ARC? In other words, is it true…
emfurry
  • 2,158
  • 2
  • 14
  • 12
118
votes
1 answer

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; ... NSMutableData *pdfData = [NSMutableData…
117
votes
6 answers

Explanation of strong and weak storage in iOS5

I am new to iOS5 development and using objective-c. I have trouble understanding the difference between strong and weak storage. I have read the documentation and other SO questions, but they all sound identical to me with no further insight. I…
KMC
  • 19,548
  • 58
  • 164
  • 253
113
votes
6 answers

To ARC or not to ARC? What are the pros and cons?

I've yet to use ARC, since the majority of the code in the project I'm working on at the moment was written pre-iOS 5.0. I was just wondering, does the convenience of not retaining/releasing manually (and presumably more reliable code that comes as…
Simon Withington
  • 1,485
  • 2
  • 11
  • 17
111
votes
3 answers

UIPopovercontroller dealloc reached while popover is still visible

I assure you that I did look for an answer in SO for my question but none of them were helpful. Here I got a simple code that should present a UIImagePickerController within a…