ARC
发布日期:2021-05-14 19:09:00 浏览次数:21 分类:精选文章

本文共 3828 字,大约阅读时间需要 12 分钟。

ARC���Automatic Reference Counting���������iOS���������������������������������

ARC������

iOS5���������������ARC���Automatic Reference Counting���������������������������LLVM3.0������������������������������������������������������������������������������������������������������retain���release���autorelease���������������������������������������������������������������������������������������������������������������������MRC���Manual Reference Counting���������������������MRC���������������������retain���release���autorelease���������������������������

������������������

���������ARC���������������������������������������������������������������������������������������������������zombie object���������������

  • ������������������alloc���new���copy������mutableCopy������������������������������������������������ARC������������������������������������������������������������������������������������������

ARC���������������

������������strong reference���

���������������������������������������������������macOS���iOS������������������������������������������������������MRC������retain���������������������������������������������������������������������������������������������������������������������

������

NSString *firstName = self.textField.text;

���������������������firstName ������������������������������������������������������������������������firstName���������������firstName������������������������������������������������

������������weak reference���

���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������

__weak NSString *weakName = self.textField.text;

���������������������weakName ������������self.textField.text������self.textField.text������������������������������������������������������������������������weakName������������nil������

���������������������������

���ARC���������������������������������������������������������������������������������������������������������������������������������������������

������

id obj = [array objectAtIndex:0];
[array removeObjectAtIndex:0];
NSLog(@"%s", obj); // Paradise lost!

������������MRC���������������������������������obj��������������������������������������������� d��vout������ARC������������������obj������������������������������������������������������������array removeObjectAtIndex:0 ���������������������obj ���������������������������������������������

������������

  • weak���������������������

    ������������������������������

  • __weak NSString *str = [[NSString alloc] initWithFormat:...];
    NSLog(@"%s", str); // ��������� "(null)"

    ������str���������������������������[[NSString alloc] ...] ���������������������������������������������������������������������

    • ���weak ������ strong���

    • ��������������������� ARC ������������������__strong������

    1. ������������
    2. property ��������������� strong ��� weak ���������������

      @property (nonatomic, strong) NSString *firstName;
      @property (nonatomic, weak) id delegate;

      ���������������������������MRC��������������������������������� strong ��� weak ������ retain���release ��� autorelease���

      1. ARC���������������
      2. ��� solvent ���������������������������������ARC���������������������������������������������������������������������������������������������������������������

        1. ���������������������
        2. ������ ARC ���������������������������������������������������������������������������������������������������������������������������������������������������������������

          ������

          ARC���Objective-C���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ARC������������������

    上一篇:IOS Sqlite的使用方法
    下一篇:iOS好的博客

    发表评论

    最新留言

    逛到本站,mark一下
    [***.202.152.39]2025年04月17日 07时41分32秒