iOS Development Review notes (3)-arc

Source: Internet
Author: User

1.ARC

When you call the release or retain statement yourself, ARC compiles the file when it is valid, and you can support both arc and non-arc code in the mashup through the-fno-objc-arc and-FOBJC-ARC two compiler flags

ARC is supported as compiled below, and the file code does not support arc

if ! __has_feature (OBJC_ARC) // This codedoes not support to ARC-(void) release{//release your var}  #endif

Integration of non-ARC third-party code in ARC Engineering: When using a third-party framework that is not compiled with arc, the files inside the compilation library need to use the-FNO-OBJC-ARC compilation switch. Edit->refactor->convert to Object-c ARC

When integrating an arc code into a non-ARC project: No compilation errors are encountered, but there may be memory leaks, in order to avoid such things, you need to use-FOBJC-ARC to mark these third-party code compiled with arc

2. Arc in the frame

1) return to zero weak reference

The weak one avoids circular hold by holding the pointer rather than the value of the reference count, but when the memory (pointer pointing to memory) is destroyed, the weak reference points to the invalid content. After the memory is destroyed, the access pointer causes the app to crash, and the zeroing reference resolves the problem by zeroing the pointer after destroying the memory.

2) Ownership modifier

ARC will automatically help us insert retain and release but we need to give it some hints to destroy the exact timing of the allocated memory, which is the title modifier

    • __strong
    • __weak
    • __unsafe_unretained
    • __autoreleasing

The first three declarations that can be used for a property declaration do not require a double underscore, and the default ownership modifier is __strong

    1. __strong

Because __strong is the default, use the

@property (Nonatomic,strong) NSString *somestring; // equivalent @property (nonatomic) NSString *somestring;

__strong equals retain.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.