【发布时间】: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