NSMutableArray alloc init vs NSMutableArray array

偶尔善良 提交于 2019-12-01 03:23:11

问题


What is the differece between:

[[NSMutableArray alloc] init]

and

[NSMutableArray array]

回答1:


Here in [NSMutableArray array] you don't have to release array it will be released automatically. & if you will write [NSMutableArray alloc] init] you will have to release array so [[NSMutableArray array] will be equivalent to [[[NSArray alloc] init] autorelease];




回答2:


The first remains in memory until you release it, the second lasts until the end of the run loop iteration.




回答3:


NSMutableArray no need to release memory and [NSMutableArray alloc] init] u must be release it.




回答4:


when ARC does work, you have to release objects come from methods including init,alloc,new,copy and mutableCopy, like [NSMutableArray alloc] init]. If not, the objects will be registered to autoreleasepool, like [NSMutableArray array].



来源:https://stackoverflow.com/questions/8557190/nsmutablearray-alloc-init-vs-nsmutablearray-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!