码迷,mamicode.com
首页 > 其他好文 > 详细

回归基础:重温ARC

时间:2016-05-17 17:28:08      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

1,ARC 是编译器做的事情(在编译期间插入内存管理相关代码)

ARC evaluates the lifetime requirements of your objects and automatically inserts appropriate memory management calls for you at compile time

2,即使是局部指针变量(属性变量、局部变量  are strong by default),所指对象引用计数也将+1

ARC ensures that oldLastName is not deallocated before the NSLog statement.

- (void)takeLastNameFrom:(Person *)person {
    NSString *oldLastname = [self lastName];
    [self setLastName:[person lastName]];
    NSLog(@"Lastname changed from %@ to %@", oldLastname, [self lastName]);
}

3,ARC仅仅维护了内存管理,其它的资源还是要手动置空或释放

(记得scrollview滑动时候退出页面 某些系统(因老的sdk中delegate为assign?)会crash)

You do not have to (indeed you cannot) release instance variables, but you may need to invoke [systemClassInstance setDelegate:nil] on system classes and other code that isn’t compiled using ARC.

4,new是可以作为属性字段名的,需要重写get方法

// Won‘t work:
@property NSString *newTitle;
 
// Works:
@property (getter=theNewTitle) NSString *newTitle;

 

回归基础:重温ARC

标签:

原文地址:http://www.cnblogs.com/xzoscar/p/5502306.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!