1

More iPhone 3 development book では、著者が更新を取得する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 とジオコーダーを autorelease プールに追加したのはなぜですか? ありがとう。

4

1 に答える 1

0

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

于 2011-12-13T23:30:12.983 に答える