【发布时间】:2011-07-23 19:56:23
【问题描述】:
以下 2 个 sn-ps 代码在性能方面有什么不同吗?
NSString* str = [[NSString alloc] initWithFormat:@"%i", 10];
// Do something with |str|.
[str release];
NSAutorelasePool* pool = [[NSAutreleasePool alloc] init];
NSString* str = [NSString stringWithFormat:@"%i", 10];
// Do something with |str|.
[pool drain];
我看到有人试图建议尽可能使用工厂方法。 尽快释放对象而不是在池耗尽时释放对象不是更好吗? 我会看到第一种类型在某些情况下非常有效,例如在紧密循环中。
【问题讨论】:
标签: objective-c memory-management nsautoreleasepool