CLLocationManager,MKReverseGeocoder,清理内存

时间:2011-06-06 05:07:33

标签: iphone objective-c cllocation mkreversegeocoder

在更多iPhone 3开发手册中,在作者完成了获取更新的 locationManager 委托方法之后,他将其置于该方法的末尾:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

    // some code here

    manager.delegate = nil;
    [manager stopUpdatingLocation];
    [manager autorelease];    
}

同样地,在 MKReverseGeocoder 委托方法中,当他完成时,他会这样做:

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {

    //some code here

    geocoder.delegate = nil;
    [geocoder autorelease];
}

为什么需要这样做才能清理内存?我认为规则是如果你分配/初始化它,你需要释放它。为什么他将locationManager和geocoder添加到自动释放池?感谢。

1 个答案:

答案 0 :(得分:0)

这样做是为了避免调用委托方法

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark

当你释放响应那些CLLocationManager/MKReverseGeocoder协议的对象