2011-06-06 29 views
1

在更多iPhone 3开发本书中,作者与获取更新的的LocationManager委托方法完成后,他把这个设在该方法的末尾:CLLocationManager,MKReverseGeocoder,清理内存

- (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]; 
} 

为什么你需要做的,为了清理MEMOR ÿ?我认为规则是如果你分配/初始化它,你需要释放它。为什么他将locationManager和geocoder添加到autorelease池?谢谢。

回答

0

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

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

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

当你的dealloc来响应这些CLLocationManager/MKReverseGeocoder协议的对象