Under what conditions does ios develop with assign, copy, retain, strong, weak, and assignretain?

Source: Internet
Author: User

Under what conditions does ios develop with assign, copy, retain, strong, weak, and assignretain?

1. assign:

Basic Types (simple type, atomic type): NSInteger, CGPoint, CGFloat, C data type (int, float, double, char, etc)

Assign applies to basic data types such as int, float, and struct, and does not apply to reference types.
Because the value type is put into the stack and follows the advanced post-exit principle, the system is responsible for managing the stack memory.
The reference type will be put into the heap. We need to manually manage the memory or use ARC to manage it.

2. copy:

Classes that contain mutable subclass that can be copied in depth, such as NSArray, NSSet, NSDictionary, NSData, NSCharacterSet, NSIndexSet, and NSString

But NSMutableArray cannot.

3. retain:

Other NSObject and its subclass objects

4. strong:

Custom object, usually strong

_ Btn = [[UIButtonalloc] init];

[Self. viewaddSubview: _ btn];

5. weak:

(1) Use weak for wire dragging with storyboard

(2) manually create controls

UIButton * btn = [[UIButton alloc] init];

_ Btn = btn;

[SelfaddSubview: _ btn];

Weak is applicable to delegate, block, and other reference types,

It will not cause a wild pointer problem or circular reference, which is very safe.


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.