alloc实现
经过一系列调用,最终调用了C函数的calloc方法
此时并没有设置引用计数为1
retain实现
//通过哈希查找,查找到对应的table表
SideTable& table = SideTables()[this];
//通过哈希查找,查找到具体的引用计数值
size_t& refcntStorage = table.refcnts[this];
//加1操作
refcntStorage += SIDE_TABLE_RC_ONE;
SIDE_TABLE_RC_ONE
为宏定义,并非为实际的1
,因为储存引用计数开始于第二位(0.1.2.3…),这里实际为4
,得到的的结果实际就是加1操作
release实现
//通过哈希查找,查找到对应的table表
SideTable& table = SideTables()[this];
//根据当前对象指针,查找到所对应的引用计数表
RefcountMap::iterator it = table.refcnts.find(this);
//减1操作
it->second -= SIDE_TABLE_RC_ONE;
retainCount实现
//通过哈希查找,查找到对应的table表
SideTable& table = SideTables()[this];
size_t& refcnt_result = 1;
//根据当前对象指针,查找到所对应的引用计数表
RefcountMap::iterator it = table.refcnts.find(this);
//向右偏移再加1
refcnt_result+= it->second >> SIDE_TABLE_RC_SHIFT;
dealloc实现

object_dispose()实现
- 开始
- objc_destructInstance()
- C函数free()
- 结束
objc_destructInstance()实现

clearDeallocting()实现

网友评论