Automatic Reference Counting in Objective-C

Discussion in 'Mac Programming' started by kainjow, Jun 15, 2011.

  1. Moderator emeritus


    Jun 15, 2000
    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.

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

    Should be some welcomed improvements.
  2. macrumors 6502a

    Dec 29, 2009
    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:
  3. macrumors 604

    Aug 9, 2009
    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.
  4. macrumors 65816


    Dec 16, 2010
    I have only looked at this briefly, but I can see this bringing in the coding convenience of garbage collection without the runtime overhead.
  5. macrumors G5


    Nov 25, 2005
    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.
  6. Moderator emeritus


    Jul 24, 2002

    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.
  7. macrumors 6502a


    Oct 26, 2003
    Richmond, VA
    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?
  8. macrumors 6502

    Jun 17, 2007
    If you pay for the Mac program, you should be able to download Lion (required) and Xcode 4.2.
  9. macrumors 65816


    Dec 16, 2010
    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.

Share This Page