NSMutableArray alloc init 与 NSMutableArray 数组
有什么区别:
[[NSMutableArray alloc] init]
和
[NSMutableArray array]
What is the differece between:
[[NSMutableArray alloc] init]
and
[NSMutableArray array]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在
[NSMutableArray array]
中,您不必释放array
它会自动释放。 &如果你要写[NSMutableArray alloc] init]
你将必须释放array
所以[[NSMutableArray array]
将相当于[[[NSArray alloc] init] autorelease];
Here in
[NSMutableArray array]
you don't have to releasearray
it will be released automatically. & if you will write[NSMutableArray alloc] init]
you will have to releasearray
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.
NSMutableArray
不需要释放内存,[NSMutableArray alloc] init]
你必须释放它。NSMutableArray
no need to release memory and[NSMutableArray alloc] init]
u must be release it.当ARC工作时,你必须释放来自init,alloc,new,copy和mutableCopy等方法的对象,例如[NSMutableArray alloc] init]。如果没有,对象将被注册到autoreleasepool,如[NSMutableArray array]。
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].