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