PDA

View Full Version : Automatic Reference Counting in Objective-C




kainjow
Jun 15, 2011, 10:24 PM
For those who haven't heard, there is a new way of dealing with memory management in Cocoa starting with 10.7/iOS 5 called Automatic Reference Counting (ARC) that has just been made public (http://lists.cs.uiuc.edu/pipermail/cfe-dev/2011-June/015588.html).

From the spec (http://clang.llvm.org/docs/AutomaticReferenceCounting.html#meta):
Automatic Reference Counting implements automatic memory management for Objective-C objects and blocks, freeing the programmer from the need [to] explicitly insert retains and releases.

One addition to this change is the @autorelease{} statement that replaces the need to use NSAutoreleasePool.

Should be some welcomed improvements.



Blakeasd
Jun 15, 2011, 11:11 PM
It seems stupid though that IOS devs get it first with Xcode 4.2. I pay $99 for the Mac program, yet IOS devs pay $99 and get it first. :mad:

chown33
Jun 16, 2011, 12:04 AM
Mac programmers already have full garbage collection. For free. Right now. Works on 10.5 and 10.6. 32-bit and 64-bit.

I don't see that this adds a lot.

jiminaus
Jun 16, 2011, 01:55 AM
Mac programmers already have full garbage collection. For free. Right now. Works on 10.5 and 10.6. 32-bit and 64-bit.

I don't see that this adds a lot.

I have only looked at this briefly, but I can see this bringing in the coding convenience of garbage collection without the runtime overhead.

gnasher729
Jun 16, 2011, 03:32 AM
Mac programmers already have full garbage collection. For free. Right now. Works on 10.5 and 10.6. 32-bit and 64-bit.

I don't see that this adds a lot.

It's very useful if you have code that you share between MacOS X and iPhone / iPad. I do, which meant no garbage collection in MacOS X for me because it doesn't work on the iPhone.

robbieduncan
Jun 16, 2011, 04:49 AM
http://forums.macrumors.com/showthread.php?t=1164724

Mac programmers already have full garbage collection. For free. Right now. Works on 10.5 and 10.6. 32-bit and 64-bit.

I don't see that this adds a lot.

It removes the run-time overhead of garbage collection. This can be quite significant, especially in performance critical code. As ARC is done at compile time you get the full performance of the reference counted environment without managing retain/release yourself.

GorillaPaws
Jun 16, 2011, 07:07 AM
While this is great news, there's a sick part of me that likes reference counting. Retain/release memory management forces me to always consider each object's lifecycle and the interaction/ownership of the object graph. I also like driving cars with manual transmissions if that tells you anything. If I were a better programmer, I would probably be more excited about GC and ARC, because memory management does become tedious.

In theory, will this open up the door for some further new innovations in the Static Analyzer that were previously impossible?

amorya
Jun 18, 2011, 06:55 AM
It seems stupid though that IOS devs get it first with Xcode 4.2. I pay $99 for the Mac program, yet IOS devs pay $99 and get it first. :mad:

If you pay for the Mac program, you should be able to download Lion (required) and Xcode 4.2.

jiminaus
Jun 18, 2011, 07:00 AM
If you pay for the Mac program, you should be able to download Lion (required) and Xcode 4.2.

XCode 4.2 is only available under iOS SDK beta, therefore it's only available to paid iOS developers. Even though there are versions for both Snow Leopard and Lion, and ARC works under Mac OS X as well as iOS. The Mac OS X Lion part of Mac Dev Centre still only has XCode 4.1 DP6, I would expect that to change to XCode 4.2. I can't see any reason for restricting Mac OS X developers to XCode 4.1.