使用temp进行分配,为什么这种方法更好? [英] Allocation using temp, why is this way better?
本文介绍了使用temp进行分配,为什么这种方法更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//.h file
@property(nonatomic, retain) NSMutableDictionary *data;
//.m file
NSMutableDictionary *temp = [[NSMutableDictionary alloc] init];
self.data = temp;
[temp release];
为什么这种方法(使用临时变量)比这更好
Why is this way (using temporary variable) is better than this
self.data = [[NSMutableDictionary alloc] init];
有什么区别?
推荐答案
第二种方法是泄漏新创建的字典.您可以使用:
The second way leaks the newly-created dictionary. You could use:
self.data = [NSMutableDictionary dictionary];
这将与您的第一个示例一样安全.
And it would be as safe as your first example.
已进行编辑,以将OP的更新与该问题相匹配.
这篇关于使用temp进行分配,为什么这种方法更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文