iPhone和模拟器上存在EXC_BAD_ACCESS问题

| 我在自己的代码之外得到了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\"];;
    }
}
    
已邀请:
只需先注释掉代码并运行,看看是否可以使mem错误消失,然后再次添加代码直到出现该错误,您就可以更好地了解问题所在。它可能在代码中的任何地方,因为您似乎在其中有许多未传入的对象,例如\'地点\'。
[location stopUpdatingLocation];
    
我有同样的记忆问题
[mapView setRegion:region animated:YES];
此方法不喜欢快速更新...     

要回复问题请先登录注册