alloc 和allocwithzone的区别
2013-01-30 15:28
260 查看
今天读cocoa design patterns 引发的问题 alloc和allocwithzone的存在解决了很多问题,但是还是很疑惑。(随便说句 此书中文版翻译不靠谱。。。)
下面是截自http://stackoverflow.com/的一段分析,虽然还没有体会,但是还是保留下来。
When one object creates another, it’s sometimes a good idea to make sure they’re both allocated from the same region of memory. The zone method (declared in the NSObject protocol) can be used for this purpose; it returns the zone where the receiver is located.
This suggests to me that your ivars, and any objects your classes "create" themselves could make use of
+allocWithZone:in this way, to make the instances they create in the same zone.
-(id)init { if(self =[super init]){ someIvar =[[SomeOtherClass allocWithZone:[self zone]] init]; } return self; }
相关文章推荐
- alloc 和allocwithzone的区别 参考
- Objective-C 里的 Alloc 和 AllocWithZone的区别
- alloc与allocWithZone的用法区别
- Alloc 和 AllocWithZone 区别和联系
- Alloc 和 AllocWithZone的区别
- Objective-C 里的 Alloc 和 AllocWithZone
- AllocWithZone:http://blog.sina.com.cn/s/blog_4cd8dd130101mi37.html
- allocwithzone
- alloc和allocWithZone
- allocwithzone
- [[NSString alloc] initWithFormat:@"%d",index] 和[NSString stringWithFormat:]的区别?
- allocwithzone
- [转]allocWithZone 和 单例模式
- allocwithzone
- allocWithZone
- timestamp with local time zone 和 timesatamp with time zone的区别
- new alloc allocWithZone
- Objective-C中Alloc和AllocWithZone
- OC学习之路:[NSNumber alloc]和NSNumber numberWith的区别
- 关于单例(Singleton)的示范代码:allocwithzone