Why UI controls and proxies use weak

Source: Internet
Author: User

Use of the [email protected] Property
* Weak (assign): Proxy \ui control
* Strong (Retain): Other objects (except proxy \ui control \ String objects)
* Copy: String
* Assign: Non-object type (base data type int\float\bool\ enum \ struct)

2. Why UI controls use weak
(1) UI controls can use weak or strong, but there is no need to use strong; (Note: UIWindow commonly used strong, because it does not feature the following view)
(2) Retain is iOS5 before, equivalent to strong, are strong hands, assign equivalent to weak, are weak pointers;
(3) as shown in: Viewcontroller has a self-contained view property that points to the in-memory view object and also customizes a btn attribute within Viewcontroller;
There is a Subviews property inside the view object that points to an array in memory that contains the index, the address stored in the index, corresponding to the object added to the Subviews, which is visible by the diagram, whether the btn is weak or strong, and has no effect on the button object , that is, there is no BTN attribute, the button object can also exist, because as long as the controller in the controller, the view is in, view in, view the Subviews property is in, the Subviews property in, its corresponding index array in, index array in, Then the button object must exist, so you can get a conclusion: as long as the controller is in, the controller view inside the child controls are all in, so generally use weak for UI controls, because weak pointers have some advantages over strong pointers, for example, the weak pointer is automatically emptied when it is useless, Null pointers do not have a memory leak;

3, agent why use weak?
In Uitableviewcontroller, for example, there is a TableView property inside the controller that points to a UITableView object with two properties in UITableView: Delegate and DataSource, Are assign, that is, weak pointers to delegate as an example, and the general UITableView agent is the Uitableviewcontroller controller;
For example, if two lines are strong pointers, it will cause the problem of circular reference, causing memory leaks;

Therefore, the general agent uses weak, that is, a strong one weak, will not cause the problem of circular references, of course, will not cause memory leaks;

Conclusion: In general, the control agent is the controller, and the controller has the control, so, in order not to raise the problem of circular reference, the agent generally use weak;

Why UI controls and proxies use weak

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.