The following are some of my summary. If something is wrong, I hope you will give me more advice.
We can see this code in the official document:
In the MyClass. h file
@ Interface MyClass: NSObject {MyObject * myObject ;}
@ Property (nonatomic, retain) MyObject * myObject;
@ End
In the MyClass. m file
@ Synthesize myObject;
-(Id) init {
If (self = [super init]) {
MyObject * aMyObject = [[MyObject alloc] init];
Self. myObject = aMyObject;
[AMyObject release];
}
Return self;
}
Why should we use the above assignment method? Don't self. myObject = [[MyObject alloc] init]; or myObject = [[MyObject alloc] init]; No? Don't upload objects by callback. Here are some of my opinions.
First: When self. ..................................
MyObject * aMyObject = [[MyObject alloc] init]; // aMyObject retainCount = 1;
Self. myObject = aMyObject; // myObject retainCount = 2;
[AMyObject release]; // myObject retainCount = 1;
Second: When self. is not added
MyObject * aMyObject = [[MyObject alloc] init]; // aMyObject retainCount = 1;
MyObject = aMyObject; // myObject retainCount = 1;
[AMyObject release]; // The myObject is released;