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
- __strong
Because __strong is the default, use the
@property (Nonatomic,strong) NSString *somestring; // equivalent @property (nonatomic) NSString *somestring;
__strong equals retain.