iOSRoadMap

Memory内存管理

1.内存中的5大区分别是什么?

image-20190324161722448

2.内存管理方案

2.1 NONPOINTER_ISA

2.2 散列表

image-20190324165113450

image-20190324165155926

SideTable是一张哈希表.使用多张 SideTable .因为可以提高查找效率.对象的引用计数值修改时候可能存在不同线程,需要锁保证数据安全,如果用同一张表会导致效率问题,需要使用分离锁分离操作.

3.数据结构

image-20190324165929441

4. 什么是ARC

5.引用计数管理

alloc实现

经过一系列调用,最终调用了C函数calloc,此时并没有设置引用计数为1

retain实现

SideTable &table = SideTables()[this];
//在tables里面,根据当前对象指针获取对应的sidetable

size_t &refcntStorage = table.refcnts[this];
//获得引用计数

//添加引用计数
refcntStorage += SIDE_TABLE_RC_ONE(4,位计算)

release 实现

SideTable &table = SideTables()[this];
RefcountMap::iterator it = table.refcnts.find[this];
it->second -= SIDE_TABLE_RC_ONE

retianCount

SideTable &table = SideTables()[this];
size_t refcnt_result = 1;
RefcountMap::iterator it = table.refcnts.find[this];
refcnt_result += it->second >> SIDE_TABLE_RC_SHIFT;(将向右偏移操作)

dealloc实现

deallo

弱引用管理

{
    id __weak obj1 = ob1; 
    //  => 编译 
    id objc1;
    objc_initWeak(&obj1,obj);
    //obj1弱引用对象地址,obj被修饰对象
}

添加weak变量

image-20190324170107697