Memory Management under arc (2) Reference relationship between objects and members

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.