IOS basic Memory Management Series 3-loop retain and @ class

Source: Internet
Author: User

1. @ class

  • Use Cases:For cyclic dependency, for example, Class A references Class B, and Class B also references Class;

We can see that the Person and Card references each other. If # import compilation is used, an error is returned! Therefore, when @ class is used to declare each other in two classes, no error will be reported during compilation!

  • Usage:Use the @ class name to reference a class. It indicates that it is a class.

  • # The import method contains all information about the referenced class, including the variables and methods of the referenced class. The @ class method only tells the compiler that. in the H file, B * B is only a class declaration. You do not need to know the specific information in this class. When the implementation file is actually used, to view information in Class B.
  • If there are hundreds of header files # import the same file, or these files are # improt in turn, once the first header file is slightly changed, all the classes referenced in this file need to be re-compiled. This efficiency can be imagined. In contrast, this problem will not occur when @ class is used.
  • In the. m implementation file, if you need to reference the object variables or methods of the referenced class, you also need to use the # import method to introduce the referenced class

 

2. Loop retain

  • For example, if object A retests object B, object B retests object.
  • In this way, object A and object B will never be released.

 
 
 
 <Foundation/Foundation.h>*  - ( <Foundation/Foundation.h>  - ( <Foundation/Foundation.h>   main( argc,   **person =*card =    person.card = card;     card.person = 

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.