1. Who applies, who releases, applies to a principle of object-oriented development, "pairing principle"
2. If Alloc,retain,copy,new (alloc&init) is used when instantiating an object, a corresponding release method is required
-Allocwithzone does not need a paired release
3. Tools-Static analysis tools (analyze)
It is possible to analyze the existence of a memory defect from the code structure and not run the code itself, to discover most of the problems
4. If a method needs to return an object, the object to be returned needs to be added Autorelease, and the object will be destroyed before the auto-free pool is destroyed
To achieve the effect of delayed release!
5. If you are customizing a Copy object, you need to allocate space for the object using the Allocwithzone Method!
6. If the custom object has Copy,retain (equivalent to ARC's strong)
Need to be released in the Dealloc method
7. Knowledge Point Supplement:
When do you use _name? When do you use Self.name?
-self.name is an attribute that corresponds to a Getter&setter method
Use Self.name to ensure the balance of reference counting with the default setter method
-_name is a member variable and is an in-memory instance
Use details
* * In the first use, Apple recommends using _name to assign the initial value, for example: Loadview,viewdidload method
Tip: If you use lazy loading except
* * Use _name in the Dealloc method
In the MRC setter method
-(void) SetName: (NSString *) name {
1. Determine whether the assigned name and the original _NAME member variable are saved in the same context
if (name! = _name) {
Release old values
[_name release];
_name = name;
To make a strong reference to a new value
[_name retain];
}
}
8. If you are using a class method, or another object that returns an automatic release, you need to retain it yourself, or it will be released once you run the loop!
Some details about MRC development