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
109
votes
7 answers

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 I ignore that? Does it matter?
Geekgirl
  • 1,322
  • 3
  • 11
  • 17
108
votes
3 answers

Override setter with arc

@interface Article : NSObject @property (nonatomic, strong) NSString *imageURLString; @end @implementation Class @synthesize imageURLString = _imageURLString; - (void)setImageURLString:(NSString *)imageURLString { _imageURLString =…
rowwingman
  • 5,589
  • 7
  • 33
  • 50
97
votes
2 answers

Does ARC support dispatch queues?

I'm reading apple's documentation about "Memory Management for Dispatch Queues": Even if you implement a garbage-collected application, you must still retain and release your dispatch queues and other dispatch objects. Grand Central Dispatch does…
flagg19
  • 1,782
  • 2
  • 22
  • 27
96
votes
5 answers

Weak and strong property setter attributes in Objective-C

What is the difference between weak and strong property setter attributes in Objective-C? @property(retain, [weak/strong]) __attribute__((NSObject)) CFDictionaryRef myDictionary; What is the impact and benefit? I heard that weak is not available on…
kkurni
  • 1,371
  • 1
  • 13
  • 11
96
votes
1 answer

NSString to CFStringRef and CFStringRef to NSString in ARC?

I am trying to understand the correct way of getting an NSString from a CFStringRef in ARC? Same for going the opposite direction, CFStringRef to NSString in ARC? What is the correct way to do this without creating memory leaks?
zumzum
  • 17,984
  • 26
  • 111
  • 172
87
votes
3 answers

KVO and ARC how to removeObserver

How do you remove an observer from an object under ARC? Do we just add the observer and forget about removing it? If we no longer manage memory manually where do we resign from observing? For example, on a view controller: [self.view…
drunknbass
  • 1,662
  • 1
  • 13
  • 19
86
votes
3 answers

How do I replace weak references when using ARC and targeting iOS 4.0?

I've begun developing my first iOS app with Xcode 4.2, and was targeting iOS 5.0 with a "utility application" template (the one that comes with a FlipsideViewController). I read that since ARC is a compile-time feature, it should be compatible with…
Mason G. Zhwiti
  • 6,444
  • 11
  • 61
  • 97
86
votes
7 answers

Sending an HTTP POST request on iOS

I'm trying to send an HTTP Post with the iOS application that I'm developing but the push never reaches the server although I do get a code 200 as response (from the urlconnection). I never get a response from the server nor does the server detect…
85
votes
4 answers

ARC forbids Objective-C objects in structs or unions despite marking the file -fno-objc-arc

ARC forbids Objective-C objects in structs or unions despite marking the file -fno-objc-arc? Why is this so? I had the assumption that if you mark it -fno-objc-arc you don't have this restriction.
Zsolt
  • 3,648
  • 3
  • 32
  • 47
84
votes
4 answers

ARC - The meaning of __unsafe_unretained?

Just want to make sure that I got it right: Do I need to __unsafe_unretain objects that I don't own? If an object is __unsafe_unretained Do I need to use assign in the @property? Does that mean that the object is not retained, and just refers to…
shannoga
  • 19,649
  • 20
  • 104
  • 169
83
votes
2 answers

Cannot use respondsToSelector using ARC on Mac

When I call respondsToSelector in an ARC environment, I get the following error message Automatic Reference Counting Issue No known instance method for selector respondsToSelector: This is the header #import @class…
David
  • 14,205
  • 20
  • 97
  • 144
83
votes
13 answers

Is it possible to debug "Terminated due to memory error"?

In a certain (consistent) point when my app is running, I consistently get the xcode error message Terminated due to memory error. I cannot find the code causing the error, but I can tell what code is near the error (using breakpoints). The error…
Andrew
  • 15,357
  • 6
  • 66
  • 101
80
votes
4 answers

@property definitions with ARC: strong or retain?

Using Xcode 4.2 and ARC, I notice that the auto-generated code for an NSManagedObject still reads like this for properties: @property (nonatomic, retain) NSString * someString; 1) Shouldn't retain now be replace with strong or weak? 2) Why does the…
80
votes
2 answers

How to enable ARC for a single file

I want to bring a single Objective-C class written using ARC into an old project. The internet provides many references for how to enable ARC for your project and then disable it for single files but I want to do the opposite. I want to leave the…
Carlton Gibson
  • 7,278
  • 2
  • 36
  • 46
76
votes
4 answers

What is the equivalent of @autoreleasepool in Swift?

In Swift, I notice there is no @autoreleasepool{} construct, although Swift does use ARC. What is the proper way to manage an autoreleasepool in Swift, or has it been removed for some reason?
Skotch
  • 3,072
  • 2
  • 23
  • 43