【问题标题】:Analyzer reports that the following code leakAnalyzer 报告以下代码泄漏
【发布时间】:2012-05-31 05:28:05
【问题描述】:

Analyzer 报告以下代码存在潜在的内存泄漏。任何人都可以对此有所了解吗?我正在释放已分配的注解。

  -(AddressAnnotation *)addAdress:(NSString*)placeTitle SubTitle:(NSString*)placeSubTitle Coordinate:(CLLocationCoordinate2D)coord withId:(NSInteger) placeId{
        AddressAnnotation *annotation = [[AddressAnnotation alloc] initWithCoordinate:coord];
        annotation.placeTitle = placeTitle;
        annotation.placeSubTitle = placeSubTitle;
        annotation.museumId = placeId;
        [mapView addAnnotation:annotation]; 
        return annotation;

        [annotation release];
    }

【问题讨论】:

  • 改为在分配它的行中将其更改为自动释放。
  • 等一下,Objective-C的return语句后面可以放点东西吗?
  • @TiagoPeczenyj:不,不是。这就是 hunumanDev 的代码泄露的原因。

标签: iphone objective-c ios memory-management analyzer


【解决方案1】:

你在返回后释放,所以永远不会被调用。 另请注意,添加注释时,地图视图会保留注释。

【讨论】:

    【解决方案2】:

    改变

    return annotation;
    [annotation release];
    

    到

    return [annotation autorelease];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-01
      • 2015-07-14
      • 1970-01-01
      • 1970-01-01
      • 2014-03-10
      相关资源
      最近更新 更多