简体   繁体   中英

How does ARC determine whether to use retain or copy?

As LLVM compiler with ARC option add retain, copy,release and autorelease for us automatically, but how does ARC determine whether to use retain or copy? Thanks in advance:)

ARC doesn't add copy , that's still your responsibility if you need copies. It only manages retain and release for you. If you manually copy something though it knows that you get a new object that it will have to release at some time.

As mentioned in following docs ( 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. It does not provide a cycle collector; users must explicitly manage the lifetime of their objects, breaking cycles manually or with weak or unsafe references.

Also you can go through the discussion of this thread - How does the new automatic reference counting mechanism work?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM