0


这是我的片段:

- (id) initWithFrame:(CGRect)frame andConfig:(PGParams*) params 
{

 for (int i=0; i<[conf.map count]; i++) 
  [conf.map replaceObjectAtIndex:i withObject:
      [[NSString alloc] initWithFormat:@"%@&sito=%@", 
       [conf.map objectAtIndex:i], [params sito]]];

 for (int i=0; i<[conf.orto count]; i++) 
   [conf.orto replaceObjectAtIndex:i withObject:
      [[NSString alloc] initWithFormat:@"%@&sito=%@", 
       [conf.orto objectAtIndex:i], [params sito]]];

 for (int i=0; i<[conf.mix count]; i++) 
    [conf.mix replaceObjectAtIndex:i withObject:
      [[NSString alloc] initWithFormat:@"%@&sito=%@", 
       [conf.mix objectAtIndex:i], [params sito]]];

}

RUN_CLANG_STATIC_ANALYZER使用选项(属性->构建选项->运行静态分析器)编译此代码,它向我显示了[[NSString alloc] ....

RUN_CLANG_STATIC_ANALYZER

激活此设置将导致 Xcode 对合格的源文件运行 Clang 静态分析工具。该工具目前支持 C 和 Objective-C 文件。[RUN_CLANG_STATIC_ANALYZER]


我该如何解决?

在此先感谢,
阿尔贝托

4

1 回答 1

3

对。您正在分配一个您拥有的对象(因为您调用了+alloc),但是您永远不会释放它。

您可以替换所有实例[[NSString alloc] initWithFormat:...][NSString stringWithFormat:...]修复泄漏。

于 2010-12-11T19:02:06.917 回答