【iOS-内存管理】

2018-09-26  本文已影响10人  GeniusWong

copy和mutableCopy

copy mutableCopy
NSString NSString浅拷贝 mutableCopy深拷贝
NSSMutableString NSString深拷贝 mutableCopy深拷贝
NSArray 同上 同上
NSMutableArray 同上 同上
NSDictionary 同上 同上
NSMutableDictionary 同上 同上

引用计数的存储

struct SideTable {
    spinlock_t slock;
    RefcountMap refcnts;
    weak_table_t weak_table;
}

dealloc

dealloc
_objc_rootDealloc
rootDealloc
object_dispose
objc_destructInstance
free

void *objc_destructInstance(id obj) 
{
    if (obj) {
        // Read all of the flags at once for performance.
        bool cxx = obj->hasCxxDtor();
        bool assoc = obj->hasAssociatedObjects();

        // This order is important.
        if (cxx) object_cxxDestruct(obj);// 清除成员变量
        if (assoc) _object_remove_assocations(obj);
        obj->clearDeallocating();// 指向当前对象的弱指针置为nil
    }

    return obj;
}

自动释放池

上一篇 下一篇

猜你喜欢

热点阅读