美文网首页iOS
alloc&init 底层设计原理探索

alloc&init 底层设计原理探索

作者: 沐知家的玩具店 | 来源:发表于2019-03-12 22:54 被阅读39次

    alloc底层探索第一步,先去苹果开发者上下载一份 objc-750源码

    根据源码可以看到alloc完整的流程图,如上图

    alloc是系统给对象分配内存空间,init是给对象进行实例化

    最后

    // Use raw pointer isa on the assumption that they might be

            // doing something weird with the zone or RR.

            obj->initIsa(cls);

    返回类的实例对象

    init的底层

    id

    _objc_rootInit(id obj)

    {

        // In practice, it will be hard to rely on this function.

        // Many classes do not properly chain -init calls.

        return obj;

    }

    返回自己,什么都没有做啊,工厂模式是为了subClass 重写 初始化赋值

    相关文章

      网友评论

        本文标题:alloc&init 底层设计原理探索

        本文链接:https://www.haomeiwen.com/subject/xxxeaftx.html