美文网首页
[[NSMutableArray alloc]init]和[NS

[[NSMutableArray alloc]init]和[NS

作者: frola_ | 来源:发表于2018-11-27 14:33 被阅读0次

[[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);

相关文章

网友评论

      本文标题:[[NSMutableArray alloc]init]和[NS

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