NSGarbageCollector

Discussion in 'iOS Programming' started by spilakalb, Oct 10, 2012.

  1. spilakalb macrumors member

    Joined:
    Sep 23, 2012
    #1
    Can we use NSGarbageCollector class for memoer management in iPhone apps? Or is it only for Mac Programming?
     
  2. MattInOz macrumors 68030

    MattInOz

    Joined:
    Jan 19, 2006
    Location:
    Sydney
    #2
    Nope it's not in iOS and is never likely to be. It's deprecated on OS X as well.
    Use ARC, let Apple's/LLVM's smartest engineers do your Memory Management.
     
  3. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #3
    As the other poster says, you can't. It is/was Mac OS only. (Thank god).

    The garbage collector was a failed experiment. It was too slow for real-world development. It would cause UI "stutters" if the program ran the garbage collector during a critical user activity like drawing a free-form line on the screen.)

    ARC is lightning fast and offers many of the same ease-of-use benefits.

    About the only thing ARC doesn't handle that the garbage collector did handle is avoiding retain cycles. (If object A has a strong reference to object B, and object B also has a strong reference to object A, they'll never get released unless you clear one of the references. In the garbage collector, objects had to be be referenced by a known location in your program or they would be released, so it would automatically free object A and object B unless you had another strong reference to them somewhere.)
     

Share This Page