__block typeof的说明
2013-12-12 13:48
267 查看
1. block不是Object对象,所以对retain无效,要想保留block生命周期,最好通过copy来实现,当然copy后,要记得release。
2.一般被block的应用的对象,retainCount会自动加1,为了解决这种 retain的内存问题,可以在对象前加__block,如果不加会导致内存泄漏,导致程序直接崩溃。加了block块就不会维护这个对象了。
对临时变量的引用:
__block Object obj = [[[Object alloc] init] withBlock:^{
[obj blockRetain];
[obj release];
}]; 这样Object的dealloc方法就会调用。
对实例变量的引用:
Object obj =[[[Object alloc] init] withBlock:^{
[self blockRetain];
}];
这样即使调用的self自身类的release方法,只要这个block没有执行完,self也不会释放。可采用如下做法
__block typeof (self) bself = self; 即通过表达式引用,指明 bself 是self类型。
Object obj =[[[Object alloc] init] withBlock:^{
[bself blockRetain];
}];
这样块和self相互独立了。
2.一般被block的应用的对象,retainCount会自动加1,为了解决这种 retain的内存问题,可以在对象前加__block,如果不加会导致内存泄漏,导致程序直接崩溃。加了block块就不会维护这个对象了。
对临时变量的引用:
__block Object obj = [[[Object alloc] init] withBlock:^{
[obj blockRetain];
[obj release];
}]; 这样Object的dealloc方法就会调用。
对实例变量的引用:
Object obj =[[[Object alloc] init] withBlock:^{
[self blockRetain];
}];
这样即使调用的self自身类的release方法,只要这个block没有执行完,self也不会释放。可采用如下做法
__block typeof (self) bself = self; 即通过表达式引用,指明 bself 是self类型。
Object obj =[[[Object alloc] init] withBlock:^{
[bself blockRetain];
}];
这样块和self相互独立了。
相关文章推荐
- ORA-600 [2662] Block SCN is ahead of Current SCN 处理方法 说明
- ORA-600 [2662] Block SCN is ahead of Current SCN 处理方法 说明
- ORA-600 [2662] Block SCN is ahead of Current SCN 处理方法 说明
- ORA-600 [2662] Block SCN is ahead of Current SCN 处理方法 说明
- ORA-600 [2662] Block SCN is ahead of Current SCN 处理方法 说明
- ORA-600 [2662] Block SCN is ahead of Current SCN 处理方法 说明
- ORA-600 [2662] Block SCN is ahead of Current SCN 处理方法 说明
- ORA-600 [2662] Block SCN is ahead of Current SCN 处理方法 说明
- ios __block typeof 编译错误解决
- ORA-600 [2662] Block SCN is ahead of Current SCN 处理方法 说明
- ORA-600 [2662] Block SCN is ahead of Current SCN 处理方法 说明
- __block typeof 编译错误解决
- Oracle 块修改跟踪 (Block Change Tracking) 说明
- iOS Interface builder was unable to determine the type of xxx.xib / xxx.storyboard
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- iOS开发bug消灭之:Could not cast value of type 'UINavigationController' to 'RedShirt.AddEmployeeTableVi...
- Could not create task or type of type: junit
- Python TypeError: return arrays must be of ArrayType
- what is the mean of "GPRINT Type" in cacti
- 浅析container_of(ptr, type, member)