[[NSMutableArray alloc]init]和[NS

2018-11-27  本文已影响0人  frola_

[[NSMutableArray alloc]init] alloc分配内存,init初始化,需要手动释放
[NSMutableArray array] 不需要手动release,遵循autoreleasepool机制
在ARC(自动引用计数)中两种方式并没什么区别

[[NSMutableArray alloc]init] alloc编译器模拟代码

/*编译器的模拟代码 */
        id pool = objc_autoreleasePoolPush();
        id obj = objc_msgSend(NSMutableArray ,@selector(alloc));
        objc_msgSend(obj,@selector(init));
        objc_autorelease(obj);
        objc_autoreleasePoolPop(pool);

[NSMutableArray array]编译器模拟代码

/*编译器的模拟代码 */
      id pool = objc_autoreleasePoolPush();
        id obj = objc_msgSend(NSMutableArray ,@selector(array));
        objc_retainAutoreleasedReturnValur(obj);
        objc_autorelease(obj);
        objc_autoreleasePoolPop(pool);
上一篇 下一篇

猜你喜欢

热点阅读