search

Home  >  Q&A  >  body text

apple - objective-c从哪个版本开始就不用手动管理内存了?

下载了xcode5,写代码时对一个变量比如NSString *str = [[NSString alloc] init]类似这样的写法,都不用手动释放内存了么?([str release])。这个特性是从xcode哪个版本开始的?
还有,那这样是不是意味着xcode5就是像java那样的自动管理内存了呢?

PHP中文网PHP中文网2769 days ago617

reply all(4)I'll reply

  • ringa_lee

    ringa_lee2017-04-21 11:20:14

    2.0
    2.0 adds GC

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-21 11:20:14

    Are you actually looking for an article here? "The Story Behind Mac OS X (8) LLVM Compilation Toolchain by Three Good Students Chris Lattner"

    reply
    0
  • 阿神

    阿神2017-04-21 11:20:14

    From iOS 5. Xcode 4.2.

    reply
    0
  • 阿神

    阿神2017-04-21 11:20:14

    So far Objective-C developers can have several methods to manage memory, the most common one is [object dealloc].

    MRC: Each time [object retain] is referenced, the reference count will be +1, and [object release] will be used to prevent accidental release and wild pointers.

    GC: This is only supported by Cocoa. NSGarbageCollector can implement automatic garbage collection similar to Java. The disadvantage is that it affects performance, so Cocoa Touch does not provide this function.

    ARC: This is a new feature (not actually new). Xcode’s new default compiler, Apple LLVM, replaces the previous LLVM-GCC and uses Clang as the front end. Clang comes with a static analyzer, which performs compilation before the code is compiled. It will be analyzed, and where retain and release need to be added, the analyzer will complete them on your behalf. ARC can take over a large number of manual reference counting operations and avoid many mistakes. After using ARC, it is forbidden to manually use the retain and release methods. You can overload dealloc but only implement customized releases.

    I have been researching this recently. Please correct me if there are any mistakes

    reply
    0
  • Cancelreply