MapView和dealloc IOS

时间:2012-02-24 18:58:49

标签: iphone objective-c memory android-mapview dealloc

你好我有一个mapView,我认为离开mapView后需要太多内存

这是我的方法有什么遗漏?

- (void)viewDidUnload
{

    mapView.showsUserLocation = NO; b
    [mapView removeAnnotations:mapView.annotations]; 

    [super viewDidUnload];

}


-(void)dealloc{
    [name release];
    [type release];
    [address release];
    mapView.delegate = nil;

    [super dealloc];
}

- (void)viewDidLoad{
    foundLocation = location found <----   

    MKCoordinateRegion region;
    region.center.latitude = foundLocation.coordinate.latitude;
    region.center.longitude=foundLocation.coordinate.longitude;
    region.span.longitudeDelta=0.01;
    region.span.latitudeDelta=0.01;
    [mapView setRegion:region animated:NO];

    ann = [[MapAnnotation alloc]init];
    ann.title = name;
    ann.subtitle = type;
    ann.coordinate=region.center;
    [mapView addAnnotation:ann];
    [ann release];

    self.navigationItem.title=@"Map";
    [super viewDidLoad];
}

地图视图还显示用户位置我认为viewDidUnload方法中缺少某些内容....

MapAnnotation是一个显示注释的类,只包含标题和副标题。

我认为即使我离开mapView,该应用仍会跟踪用户的位置。

1 个答案:

答案 0 :(得分:2)

将委托设置为nil后,您没有调用[mapView release]