Cocoa 哪种方式创建对象?例如NSArray
来源:互联网 发布:民用枪持枪证 知乎 编辑:程序博客网 时间:2024/06/12 22:45
《programming is iOS4》有一段写到:
Many classes provide the programmer with two equivalent ways to obtain an object: either an autoreleased object or an object that you create yourself withalloc and some form of init. So, for example, NSArray supplies both the class method arrayWith- Objects: and the instance method initWithObjects:. Which should you use? On the whole, Apple would prefer you to lean towardinitWithObjects:. In general, where you can generate an object withalloc and some form of init, they’d like you to do so. That way, you are in charge of releasing the object. This policy will prevent your objects from hanging around in the autorelease pool and will keep your use of memory as low as possible.
大致内容是,一般Cocoa对象都提供两种方式创建,如NSArray提供 arrayWith- Objects 和 initWithObjects两种。总体来说,苹果建议使用第二种,因为可以手动管理对象的内存释放。第一种类方法创建,其实是把对象放入autorelease pool ,在适当的时候释放,这样的话容易造成内存升高。
- Cocoa 哪种方式创建对象?例如NSArray
- 哪种遍历NSArray/NSDictionary方式快?
- 遍历NSArray的四种方式
- NSArray的4种遍历方式
- NSArray的4种遍历方式
- NSArray的4种遍历方式
- NSArray的4种遍历方式
- NSArray的4种遍历方式
- 创建XMLHttpRequest对象的两种方式
- JS 创建对象的几种方式
- Java创建对象的三种方式
- Javascript创建对象的两种方式
- JavaScript 创建对象的几种方式
- js创建对象的几种方式
- JavaScript创建对象的几种方式
- spring3种创建对象的方式
- java创建对象的四种方式
- c++创建对象的两种方式
- oracle数据库导入、导出dmp文件
- Android-Socket-SocketDemo-AndroidStudio
- test
- java笔试题及解答专辑201710241407
- Can't create handler inside thread that has not called Looper.prepare()
- Cocoa 哪种方式创建对象?例如NSArray
- win10安装64位Pygame
- 倍增求快速幂,乘法
- 文章标题 nginx 实现express 高并发接口
- spring StopWatch 简单便捷的计时器
- Python 的帮助--help、dir、type
- C++中的构造函数
- CAD版本转换怎么做
- Perm