First, the basic operation of the counter
1> retain: +1
2> Release:-1
3> Retaincount: Get counter
Ii. memory management of Set method
Implementation of 1> Set method
-(void) Setcar: (Car *) car
{
if (_car! = car)
{
[_car release];
_car = [car retain];
}
}
2> implementation of the Dealloc method (do not call Dealloc directly)
-(void) dealloc
{
[_car release];
[Super Dealloc];
}
Three, @property parameters
1> OC Object Type
@property (nonatomic, retain) class name * attribute name;
@property (nonatomic, retain) Car *car;
@property (nonatomic, retain) ID car;
Properties that have been retain, must be in the Dealloc method release property
-(void) dealloc
{
[_car release];
[Super Dealloc];
}
2> non-OC object type (int\float\enum\struct)
@property (nonatomic, assign) type name attribute name;
@property (nonatomic, assign) int age;
Iv. autorelease
1. In the system's own method, if it does not contain alloc, new, copy, then the objects returned by these methods are already autorelease
[NSString stringWithFormat: ....];
[NSDate Date];
2. Development often write some kind of method to quickly create a Autorelease object
* Do not use the class name directly when creating the object, use the self
oc--Memory Management Summary