Ios arc mechanism and iosarc Mechanism
IOS ARC memory automatic management mechanism, currently, almost a lot of projects will use ARC, because it releases the memory to work, but although ARC is good, we still cannot leave memory management alone.
How ARC works:
ARC is a pre-compilation step. It automatically adds the retain/release/autorelease statement to our code.
ARC does not collect garbage, and the reference count does not disappear, but it becomes automatic. It sounds like an append feature. However, as long as we think about how many features of Objective-C are implemented through preprocessing of source files, we won't think so.
// The following is an example:
This is the case when we use ARC.
NSObject *obj = [[NSObject alloc]init]; // Do any additional setup after loading the view, typically from a nib.
This is true with ARC.
NSObject *obj = [[NSObject alloc]init]; [obj release];
Here are some official introductions
After the emergence of ARC, some new rules emerged: (source)
1. The method for creating an object using Alloc/Init is the same as before, but you cannot call retain/release/autorelease/retainCount. You cannot use the selector to secretly call them: Do not use @ selector (retain) or @ selector (release ).
2. dealloc Method
If ARC is automatically called for you, you must not directly call dealloc. However, if you need to release resources other than instance variables, you can still create a custom dealloc method. In this method, do not call [super dealloc]. Because ARC will help you tune it.
3. Declared attributes
Before ARC, we used the assign/retain/copy parameter in the @ property command to tell the compiler how to manage the memory of these attributes. After ARC is used, these parameters are voided and the weak/strong parameters are used.
4. object pointer in the C structure
It is also forbidden to use. We recommend that you do not put them in the structure and change them to the class. Otherwise, the ARC will not recognize them. Some porting problems may occur. However, ARC can be closed in files. Refer to "introduce codes that are incompatible with ARC" below ".
5. Replace @ autoreleasepool with the NSAID utoreleasepool
ARC-compatible Code cannot use the NSAID utoreleasepool object. Instead, use the @ autoreleasepool {} block instead. A good example:
int main(int argc, char *argv[]){ @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([ExampleAppDelegate class])); }}