Allocation using temp, why is this way better?

后端 未结 1 1767
被撕碎了的回忆
被撕碎了的回忆 2021-01-17 02:29
//.h file
@property(nonatomic, retain) NSMutableDictionary *data;

//.m file
NSMutableDictionary *temp = [[NSMutableDictionary alloc] init];
self.data = temp;
[temp          


        
相关标签:
1条回答
  • 2021-01-17 03:23

    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.

    Edited to match OP's update to the question.

    0 讨论(0)
提交回复
热议问题