iOS:NSMutableArray alloc / init和arrayWithObjects之间的区别: [英] iOS: Difference between NSMutableArray alloc/init and arrayWithObjects:

查看:518
本文介绍了iOS:NSMutableArray alloc / init和arrayWithObjects之间的区别:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之间

  NSMutableArray * p = [[NSMutableArray alloc] initWithObjects: ...] 

  NSMutableArray * p = [NSMutableArray arrayWithObjects:...] 


解决方案

在第一个,你有所有权的数组对象&你必须释放它们。

  NSMutableArray * p = [[NSMutableArray alloc] initWithObjects:...] 
[p release];

&最后一个你不需要发布,因为你没有数组对象的所有权。

  NSMutableArray * p = [NSMutableArray arrayWithObjects :...] //这是自动释放的

如果你调用release中的,那么它会崩溃你的应用程序。 p>

What is the difference between

NSMutableArray* p = [[NSMutableArray alloc] initWithObjects:...]

and

NSMutableArray* p = [NSMutableArray arrayWithObjects:...]

解决方案

In the first one, you have the ownership of array object & you have to release them.

NSMutableArray* p = [[NSMutableArray alloc] initWithObjects:...];
[p release];

& last one you dont need to release as you don't have the ownership of array object.

NSMutableArray* p = [NSMutableArray arrayWithObjects:...]; //this is autoreleased

If you call release in this, then it will crash your application.

这篇关于iOS:NSMutableArray alloc / init和arrayWithObjects之间的区别:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆