CLLocationManager、MKReverseGeocoder、清理内存

发布于 2024-11-13 10:00:04 字数 731 浏览 3 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屋顶上的小猫咪 2024-11-20 10:00:04

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

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

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

当您释放响应这些 CLLocationManager/MKReverseGeocoder 协议的对象时

This is done to avoid calling the delegate methods

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

or

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

when you dealloc the object that responds to those CLLocationManager/MKReverseGeocoder protocols

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文