The difference between OC __weak and __strong

Source: Internet
Author: User

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

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.