iOS 内存中的ViewController释放

程序开发中,使用到ViewController是常事。但是有时候因为使用的不当,导致其不能被自动回收,从而引起一些隐含的Bug。或者从编码的角度来说,让人觉得不舒服。因为内存中有些东西没有CleanUp。

下面列举几点:


1)ViewController的self释放的三种情况
  1.1 delegate没有置空nil
  1.2 block循环引用,应当在block中使用weakSelf来引用:__weak typeof(self) weakSelf = self; 
  1.3 NSTimer必须先停止(invalidate)然后nil掉。

2)[controller.view removeFromSuperview];   从父控件上移除自己,引用-1


3)controller.view = nil;   释放View


4)controller = nil;   释放ViewController

原文地址:https://www.cnblogs.com/vokie/p/4876159.html