简体   繁体   中英

NSMutableArray alloc init vs NSMutableArray array

What is the differece between:

[[NSMutableArray alloc] init]

and

[NSMutableArray array]

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

第一个保留在内存中直到你释放它,第二个持续到运行循环迭代结束。

NSMutableArray不需要释放内存和[NSMutableArray alloc] init]你必须释放它。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM