我在自己的代码中获得了EXC_BAD_ACCESS。目前,我的代码通过shareURLCache对象获取URL,然后启动url连接。一旦我离开启动url连接的方法,我就点击了EXC_BAD_ACCESS。我已经尝试使用仪器找到任何僵尸,我已经分析了内存泄漏,也没有出现。此时我完全卡住了。
以下是加载网址并启动网址连接的代码
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"At new location: %@",newLocation);
MKCoordinateRegion region =
MKCoordinateRegionMakeWithDistance([newLocation coordinate], 750, 750);
[mapView setRegion:region animated:YES];
[location stopUpdatingLocation];
CLLocationCoordinate2D coord = [newLocation coordinate];
NSURL *url = [urlCache getReccomendationForUID:@"12345" atLat:coord.latitude
atLon:coord.longitude forCategories:nil];
// Create the request.
NSURLRequest *request = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
// create the connection with the request
// and start loading the data
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
if (connection) {
// Create the NSMutableData to hold the received data.
// xmlData is an instance variable declared elsewhere.
xmlData = [[NSMutableData alloc]init];
} else {
NSLog(@"Could not create connection");
}
}
来自sharedURLCache的返回url
的方法-(NSURL *)getReccomendationForUID:(NSString *)u atLat:(double)lat atLon:(double)lon forCategories:(NSArray *)cat
{
if(remote) {
NSMutableString *categories = [[NSMutableString alloc]init];
for(NSString *s in cat) {
[categories appendString:@"&cat="];
[categories appendString:s];
}
NSString *s = [NSString stringWithFormat:@"%@/recommendation?uid=%@&psw=null&lat=%f&lon=%f?%@",
apiRoot,u,lat,lon,categories];
[categories release];
return [NSURL URLWithString:s];
} else {
return [[NSBundle mainBundle] URLForResource:@"XMLTest" withExtension:@"xml"];;
}
}
答案 0 :(得分:0)
首先注释掉代码并运行以查看是否可以让mem错误消失,然后再次开始添加代码直到它出现,然后您就可以更好地了解问题所在。它可能在你的代码中的任何地方,因为你似乎有许多没有传入的对象,例如'位置'。
[location stopUpdatingLocation];
答案 1 :(得分:0)
我的内存问题与
相同[mapView setRegion:region animated:YES];
此方法不喜欢快速更新...