CLLocationManager、MKReverseGeocoder、清理内存
在 More iPhone 3 开发书中,作者在使用 locationManager 委托方法获取更新后,将其放在该方法的末尾:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
// some code here
manager.delegate = nil;
[manager stopUpdatingLocation];
[manager autorelease];
}
同样,在 MKReverseGeocoder 中em> 委托方法,当他完成后,他会这样做:
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
//some code here
geocoder.delegate = nil;
[geocoder autorelease];
}
为什么你需要这样做才能清理内存?我认为规则是如果你分配/初始化它,你需要释放它。他为什么要将locationManager和geocoder添加到自动释放池中?谢谢。
In the More iPhone 3 development book, after the author is done with the locationManager delegate method of getting updates, he puts this at the end of that method:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
// some code here
manager.delegate = nil;
[manager stopUpdatingLocation];
[manager autorelease];
}
And similarly, in the MKReverseGeocoder delegate methods, when he's done he does this:
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
//some code here
geocoder.delegate = nil;
[geocoder autorelease];
}
Why do you need to do that in order to clean up memory? I thought the rule was if you alloc/init it, you need to release it. Why does he add the locationManager and geocoder to the autorelease pool? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这样做是为了避免调用委托方法
或
当您释放响应这些
CLLocationManager/MKReverseGeocoder
协议的对象时This is done to avoid calling the delegate methods
or
when you dealloc the object that responds to those
CLLocationManager/MKReverseGeocoder
protocols