我在自己的代码之外得到了一个 EXC_BAD_ACCESS。目前,我的代码通过 shareURLCache 对象获取 URL,然后启动 url 连接。一旦我离开启动 url 连接的方法,我就会点击 EXC_BAD_ACCESS。我曾尝试使用仪器来查找任何僵尸,并且我已经分析了内存泄漏并且也没有出现。在这一点上,我完全被卡住了。
这是加载url并启动url连接的代码
- (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"];;
}
}