回归基础:重温ARC

Posted 青奥科技

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了回归基础:重温ARC相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

重温基础

重温JavaScript基础

爆肝三万字,带你重温Java基础。。。

重温四大基础数据结构:数组链表队列和栈

引用类型 [重温JavaScript基础]

逻辑回归