iOS notes, if you have any errors, please let us know, thank you
1.When you create an object using new, Alloc, or copy, the object has a
Retain count of 1. You is responsible for sending the object a release Orautorelease message when you ' re finished with it. That's the, it gets cleanedup when its useful life are over.
If you create an object with new, Alloc, copy, the object's reference counter is 1. Send the release or autorelease message to the created object when you are finished using it.
2.When you get hold of a object via any other mechanism, assume it has
A retain count of 1 and that it has already been autoreleased. You don't have a further work to make sure it gets cleaned up tneed. If you ' re goingto-on-to-the-object for any length of time, retain it and make sure torelease it when you ' re finished.
Objects obtained by other means, such as the following three lines of code
Person * s = [[person alloc]init];
Person * S1 = s;
[s retain];
S1 a non-new, Alloc, copy method to obtain an object, it is necessary to use retain, release to maintain the use of objects.
3.If you retain a object, you need to (eventually) release or autorelease it. Balance these retains and releases.
Manually manage an object to ensure that retain and release end up as much.
Ps:1. The automatically generated setter, getter method, using a pointer (reference) declared with @property (Nonatomic,retain) is as follows
-(void) Set_student: (student*) student{
if (_student! = Student) {
[_student release];
_student = [student retain];
}
}
-(student*) student{
return _student;
}
The setter and Getter will release the old object, retain the new object, so we use the dot operator, the set method without specifically retain the referenced object
2. Circular reference problem for two objects: @property (nonatomic,assign) to declare a reference to one of the objects.
OC Memory management Golden Rule