First, introduce the differences between copy, strong, weak, as shown in the code
@property (copy,nonatomic) nsmutablestring*Acopymstr, @property (strong,nonatomic) nsmutablestring*Strongmstr, @property (weak,nonatomic) nsmutablestring*Weakmstr, @property (assign,nonatomic) nsmutablestring*Assignmstr; Nsmutablestring*mstrorigin = [[Nsmutablestringalloc] initwithstring:@"Mstroriginvalue"]; Self.acopymstr=Mstrorigin; Self.strongmstr=Mstrorigin; Self.weakmstr=Mstrorigin; NSLog (@"mstrorigin output:%p,%@\\n", Mstrorigin,mstrorigin); NSLog (@"acopymstr output:%p,%@\\n", _ACOPYMSTR,_ACOPYMSTR); NSLog (@"strongmstr output:%p,%@\\n", _STRONGMSTR,_STRONGMSTR); NSLog (@"weakmstr output:%p,%@\\n", _WEAKMSTR,_WEAKMSTR); NSLog (@"reference Count%@", [Mstroriginvalueforkey:@"Retaincount"]);//Output Results//2016-09-01 15:19:13.134 lbcopy[1205:87583] mstrorigin output: 0x7892a5e0,mstroriginvalue//2016-09-01 15:19:13.135 lbcopy[1205:87583] acopymstr output: 0x7893deb0,mstroriginvalue//2016-09-01 15:19:13.135 lbcopy[1205:87583] strongmstr output: 0x7892a5e0,mstroriginvalue//2016-09-01 15:19:13.135 lbcopy[1205:87583] weakmstr output: 0x7892a5e0,mstroriginvalue//2016-09-01 15:19:13.135 lbcopy[1205:87583] Reference count 2
Conclusion:
1, copy and strong reference counter plus one, weak reference counter does not add one.
2. The memory addresses of strong and weak point to mstrorigin,copy to create a new memory address and copy the contents, and then point to Mstrorigin.
Second, modify the value of the Mstrorigin, will not affect the ACOPYMSTR, only affect Strongmstr and weakmstr
Third, the mstrorigin to Nil,strong and weak are nil,copy not nil
Iv. Assign
The Assign reference counter does not add one, but when the point is set to NULL, only the value is released. This leads to the existence of a wild pointer, that is, when the address has not been written before other values, can output normal, but once the data is re-written, the pointer may not have a value at any time, causing the crash.
The difference between the iOS OC keyword copy,strong,weak,assign