我有一个关于内存管理的快速问题,我对此不是很确定。我目前有一个调用locationManager:didUpdateToLocation:fromLocation来解析设备位置的locationManager委托。我的问题是,我正在考虑在获得[newLocation coordinate]之后添加ReverseGeoCoding,但不确定在这里进行分配,因为每次调用locationManager:didUpdateToLocation:fromLocation时,我都会分配一个新的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];
}关于这一点,有人能给我指出正确的方向吗?我确实尝试过在应用程序中执行分配:didFinishLaunchingWithOptions:但后来意识到我无法访问newLocation坐标。
EDIT_001:
DyingCactus,如果你只是添加了自动释放,委托方法不会被调用的原因,我猜是因为对象正在被释放,对吗?我想我有点糊涂了,以为MKReverseGeoCoder会留下来为我所有的电话提供服务。现在看来,对于每个locationManager:didUpdateToLocation:fromLocation,每次调用都会创建一个新的实例。这就是我现在所拥有的,感觉好多了:
// INTERFACE:
MKReverseGeocoder *reverseGeoCoding;
@property(nonatomic, retain) MKReverseGeocoder *reverseGeoCoding;。
// IMPLEMENTATION:
self setReverseGeoCoding:[[[MKReverseGeocoder alloc] initWithCoordinate:location] autorelease]];
[reverseGeoCoding setDelegate:self];
[reverseGeoCoding start];非常感谢
加里
发布于 2010-05-24 22:18:39
在那里添加一个自动释放可以消除内存问题,但是委托方法将不会被调用。
要解决这两个问题,请在类级别声明反向地理编码器。有关示例,请参阅示例应用程序CurrentAddress。
此外,如果要在反向地理编码完成时调用foundLocation方法,请在反向地理编码器的didFindPlacemark方法中调用它,而不要在调用start之后立即调用它。
https://stackoverflow.com/questions/2896340
复制相似问题