OC源码分析-block (四)内存管理
2019-01-12 本文已影响8人
TianTianBaby223
一 :
__block 修饰的int age,block会对其进行强引用.

block copy操作拷贝到堆中,其使用的__block 修饰的变量,也会拷贝到堆中.

从堆中移除block时候,对所有引用的__block变量进行一次 release 操作

二 :

block对__block 修饰的 int age 变量进行一次强引用, 对NSObject 根据其__strong 或者是 __weak进行一次强引用,或者是弱引用

三 : 总结
三种变量在block中捕获

在源码中的表现


四 :forwarding指针

block 进行copy操作后,自身以及 所持有的int age 都放入了堆区,为了确保其访问的是堆空间的,age变量,所以先访问forwarding指针,forwarding指针永远指向__block自己.

五 : __block修饰的对象类型

源码中的表现

内存中表现

六 : __block __weak 修饰变量

源码中表现

内存中表现

注意 :
