NSMutableArray alloc init vs NSMutableArray array

独自空忆成欢 提交于 2019-12-01 06:00:55
Aakil Ladhani

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];

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

Ravi

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

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].

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