NSNotificationCenter addObserverForName 的释放
来源:互联网 发布:gpgpu编程技术 编辑:程序博客网 时间:2024/06/06 06:44
- 先让我们来看看正确的姿势, 一定要在想要释放内存前把持有的对象释放掉, 千万不要在dealloc 里面写, 根本没有机会走到dealloc, 这个跟NSTime 类类似的道理,[self.timer invalidate]; 要提前处理掉
@property (nonatomic, strong) id observer;- (void) viewDidLoad { self.observer = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidEnterBackgroundNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { NSLog("hello"); }];}- (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; if (self.observer) { [[NSNotificationCenter defaultCenter] removeObserver:self.observer]; self.observer = nil; }}- (void)dealloc{ NSLog(@"MTC_dealloc OK");}
下面这个兄弟写错了 , 永远不会释放掉这个UIViewControl了……
http://www.jianshu.com/p/1788d15c570b
0 0
- NSNotificationCenter addObserverForName 的释放
- NSNotificationCenter 中的addObserver和addObserverForName的释放问题。
- NSNotificationCenter 中的addObserver和addObserverForName的释放问题。
- NSNotificationCenter中的addObserverForName
- iOS: NSNotificationCenter的方法addObserverForName:object:queue:usingBlock:
- NSNotificationCenter 释放的两种方法的利弊
- NSNotificationCenter 的使用
- NSNotificationCenter 的使用
- NSNotificationCenter的作用
- NSNotificationCenter 的使用
- NSNotificationCenter 的使用
- NSNotificationCenter的作用
- NSNotificationCenter 的使用
- NSNotificationCenter 的使用详解
- NSNotificationCenter 的详细说明
- NSNotificationCenter的简单应用
- NSNotificationCenter的一个问题
- NSNotificationCenter 的使用详解
- 实现对象属性的"监控" - 修改数据后自动更新页面
- 应用更新跳转 AppStore,千万别一不小心跳到 itune,因为 itune 里的 app 没有更新按钮
- react项目中通过 iscroll 实现上拉加载,下拉刷新
- Linux系统中的动态库和静态库
- php 生成随机字符串的方法
- NSNotificationCenter addObserverForName 的释放
- Golang的...
- fopen 文本文件与二进制文件区别
- 根据不规则效果图布局方法
- SpringMVC 1(SpringMVC的结构图,Hello 的案例)
- 公钥私钥及ssh公钥无密码登录
- MySQL——常用SQL优化(一)
- Mybatis的二级缓存配置
- JVM学习笔记(五):根据字节码指令介绍方法执行流程