Memory Management under arc (2) Reference relationship between objects and members
Procedure List 2-1
myObjStrong = [[MyObject alloc] init];myObjStrong.strStrong = [array objectAtIndex:5];myObjStrong.strWeak = [array objectAtIndex:6];__weak MyObject *myObjWeak; myObjWeak = myObjStrong;
The following "releases" the strong Member of the weak object:
myObjWeak.strStrong = nil;
Consider the following output:
NSLog(@"weak object's stong member:%@", myObjWeak.strStrong);NSLog(@"strong object's strong member:%@", myObjStrong.strStrong);
Observed results
Visible:A weak object member is a strong object member.
Comparison execution:
Procedure List 2-2
myObjWeak.strWeak = nil;NSLog(@"weak object's weak member:%@", myObjWeak.strWeak);NSLog(@"strong object's strong member:%@", myObjStrong.strStrong);NSLog(@"strong object's weak member:%@", myObjStrong.strWeak);
The above output is:
Further observe the value in array
Procedure List 2-3
NSLog(@"string 5:%@", [array objectAtIndex:5]);NSLog(@"string 6:%@", [array objectAtIndex:6]);
The original string object is not released.
In fact, because of the existence of the strong attribute array, no matter whether myobjweak or myobjstrong is left empty (= nil), the string in it cannot be released;
Questions:
Put myobject into array and reference weak and strong respectively. Can I release myobject members in array by referencing them?