ARC Automatic Reference Counting learning notes

Source: Internet
Author: User

1.

In Arc, all *outlet* properties are recommended to use weak, which are already part of view Controller's view hierarchy and do not need to be defined again as strong (the effect in arc is equivalent to retain). The only outlet that should use strong is the File's Owner, which connects to the top-level object of the nib.

Because the two properties of TableView and searchbar are defined as weak, the two variables are automatically set to nil when the object they point to is freed.

When the IOS APP receives a low memory warning, the view Controller's main view is unload and all Subview are released. The UITableView and Uisearchbar objects are automatically released, zeroing weak pointer system will automatically set Self.tableview and Self.searchbar to nil. So you don't have to set it to nil again in Viewdidunload, and when Viewdidunload is called, these two properties are already nil.

This does not mean that you can not need viewdidunload, as long as you keep an object pointer, the object will survive. When you don't need an object, you can manually set the pointer to nil. As in the example code above, SoundEffect = nil; The Viewdidunload () method needs to set all non-outlet variables to nil, as well as the Didreceivememorywarning () method.

2.

The property's modifiers are summarized as follows:

    • Strong: Equivalent to "retain", property becomes owner of object

    • Weak: The property is weak pointer, which is automatically set to nil when the object is disposed, remembering Outlet

      should use Weak

    • Unsafe_unretained: Equivalent to the previous "assign", only IOS 4 should be used

    • Copy: Copy an object and create a strong association as in the previous copy

    • Assign: The object cannot use assign, but the original type (BOOL, int, float) is still

      can use

ARC Automatic Reference Counting learning notes

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.