iOS-内存管理

1. alloc, new,copy一个对象时,对象的引用计数为1

  引用计数为0时,才能释放

2. retain +1

 release -1

 retainCount 不准确

3. 对象引用计数为0需要销毁时,系统会调用-(void)dealloc方法,必须先调用[super dealloc]且要写在所有代码后面

4. ARC(Automatic Reference Counting)自动引用计数

  编译器会在适当的地方自动添加retain/release方法

 MRC(Manul Reference Counting)手动引用计数

5. 关闭ARC

6. 僵尸对象:被释放了的对象

  野指针:指向僵尸对象的指针

  Enable zoobie objects

 7. 全局断点

 8. NSLog(@"%s", __func__)

9. 给空指针发送消息是没有任何反应的,不会报错。

10. - (void)setPerson:(Person*)person{

  if(_person != person){

    [_person release];

    _person = [person retain];

}}

  - (void)dealloc{

  对象属性 release;

  [super dealloc];

}

11. @property(nonatomic, retain/assign) Person person;

  retain : 自动生成内存管理的setter代码

  assign : 生成普通的setter/getter代码,不写的话默认是assign

  

  

猜你喜欢

转载自www.cnblogs.com/yintingting/p/12668936.html