Weak references in the Objective-c

Source: Internet
Author: User

Weak references are too weak to be able to keep in touch with a request for space through this reference. As an example,

@interface Classa:nsobject

@porperty (nonatomic,weak) ClassA * TEMPCLASS1;

@property (Nonatomic,strong) ClassA * TEMPCLASS2;

-(void) test;

@end

@implement ClassA

-(void) test

{

Self.tempclass1 = [ClassA new]; Since TempClass1 is a weak reference, the reference is broken after the application is complete, and Self.tempclass1 is nil.

Self.tempclass2 = Self.tempclass1; //

Self.tempclass2 = [ClassA new]; This is OK TEMPCLASS3 is a strong reference can normally apply for a piece of space

Self.tempclass1 = Self.tempclass2; After this assignment, TempClass1 also has a goal, but if Self.tempclass2=nil, then the space will still disappear, so this time TempClass1 is still nil

}

@end

Weak references in the Objective-c

Related Article

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.