I have a quick question regarding memory management that I am not quite sure about. I currently have a locationManager delegate that calls locationManager:didUpdateToLocation:fromLocation
where it resolves the device location. My question is I am looking at adding ReverseGeoCoding after I have obtained the [newLocation coordinate]
but am unsure about doing the alloc here, as each time locationManager:didUpdateToLocation:fromLocation
gets called I will be alloc-ing a new MKReverseGeoCoder?
// LOCATION
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
// GeoCoding:
MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:[newLocation coordinate]];
[geoCoder setDelegate:self];
[geoCoder start];
[self foundLocation];
}
Can anyone point me in the right direction with regards to this? I did try doing the alloc in application:didFinishLaunchingWithOptions: but then realised I did not have access to [newLocation coordinate].
EDIT_001:
DyingCactus, the reason that the delegate methods don't get called if you just add autorelease is I guess because the object is getting released, is that right? I think I was getting confused by thinking that MKReverseGeoCoder was going to stay around and service all my calls. It now seems that for each locationManager:didUpdateToLocation:fromLocation
a new instance is created with each call. This is what I have now, which feels a lot better:
// INTERFACE:
MKReverseGeocoder *reverseGeoCoding;
@property(nonatomic, retain) MKReverseGeocoder *reverseGeoCoding;
.
// IMPLEMENTATION:
self setReverseGeoCoding:[[[MKReverseGeocoder alloc] initWithCoordinate:location] autorelease]];
[reverseGeoCoding setDelegate:self];
[reverseGeoCoding start];
many thanks
gary