当我使用 MKMapView 时,根据 Instruments,我得到了泄漏。我的代码如下:
mapView = [[MKMapView alloc] initWithFrame:self.bounds];
mapView.mapType = MKMapTypeStandard;
mapView.delegate = self;
[self addSubview:mapView];
我们释放地图视图;以下代码适用于 MKAnnotationView:
-(MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
WeatherItem *weatherItem = (WeatherItem *)annotation;
static NSString *AnnotationViewID = @"annotationViewID";
WeatherAnnotationView *annotationView = (WeatherAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil)
{
annotationView = [[[WeatherAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
SWPeripheryIndicator *perpheryIndicator = [[SWPeripheryCache sharedPeripheryCache] onePeripheryCityInfo:[weatherItem cityCode]];
if (perpheryIndicator==nil && MKMapRectContainsPoint(map.visibleMapRect, MKMapPointForCoordinate(annotation.coordinate)))
{
[[SWeatherEngine sharedSWeatherEngine] getPeriphyWeather:weatherItem.cityCode];
[onDownLoadView setObject:annotationView forKey:weatherItem.cityCode];
}
annotationView.cityCode = weatherItem.cityCode;
annotationView.annotation = annotation;
[annotationView updatePeripheryInfo:weatherItem.cityName shouldDisplayData:perpheryIndicator];
return annotationView;
}