【问题标题】:NSMutableArray Leaks in LoopNSMutableArray 循环泄漏
【发布时间】:2011-03-06 17:48:40
【问题描述】:

我正在使用仪器来查找内存泄漏,它发现了很多! 但我不知道如何解决它。

@property(nonatomic, retain) NSMutableArray *wycategories;
...
...
self.wycategories = [[NSMutableArray alloc]init];
...
...
for (CXMLElement *node in nodes) {      
    //Instruments say that here there are a lots of memory leaks
    WaiYahCategory *wycategory = [[WaiYahCategory alloc] init];

    wycategory.text = [[node childAtIndex:0] stringValue];
    wycategory.idCategory = [[node attributeForName:@"id"] stringValue];
    wycategory.desc = [[node attributeForName:@"desc"] stringValue];
    wycategory.icon = [[node attributeForName:@"icon"] stringValue];

    [self.wycategories addObject:wycategory];
    [wycategory release];
}

【问题讨论】:

    标签: iphone memory-leaks nsmutablearray


    【解决方案1】:

    由于wycategories有一个retain属性,你必须在赋值后释放数组。

    NSMutableArray *array = [[NSMutableArray alloc]init];
    self.wycategories = array; // <- The property retains the array
    [array release];
    

    【讨论】:

      猜你喜欢
      • 2013-02-11
      • 2011-07-08
      • 2011-10-15
      • 1970-01-01
      • 2012-07-29
      • 2011-01-21
      • 2011-03-23
      • 1970-01-01
      • 2014-05-17
      相关资源
      最近更新 更多