1. First on the code
ID __weak obj=[[nsobject Alloc]init]; NSLog (@ "Weak reference self Address:%p", &obj); NSLog (@ "Weak reference points to address:%p", obj); ID __strong obj0=[[nsobject Alloc]init]; ID __weak obj1=obj0; NSLog (@ "strong reference to its own address:%p", &obj0); NSLog (@ "Weak reference self Address:%p", &obj1); NSLog (@ "Strong reference point to address:%p", obj0); NSLog (@ "Weak reference points to address:%p", obj1); obj1=nil;// Obj0=nil; NSLog (@ "Weak reference is destroyed when the strongly typed variable points to address:%p", obj0); NSLog (@ "weak reference destroy when weak type variable points to address:%p", obj1);
2. Running Results
3. When a strongly typed variable is set to nil, two variables point to null
4. This shows that when a strong reference is held on a variable, a weak reference simply points to the variable and does not own it.
The difference between OC __weak and __strong