views:

127

answers:

1

Hi, i am working on a map application, in that i like to drop the pins (as in Zillow apps) when ever user change the map view. I am using following code code. i am try to load the xml data from server using NSAutoreleasepool to do the xml parsing in the background thread.

  • (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{

    NSLog(@"inside region did changed ");

    urlString =[NSString stringWithFormat: @"http://asdfasdasdf.com/asdfasdf/mapxml.php];
    
    
    [stories1 release];
    
    
    [mapview removeAnnotations:eventPoints1];
    
    
    eventPoints1 = [[NSMutableArray array] retain];
    
    
    [self performSelectorInBackground:@selector(callParsing) withObject:nil];
    

}

-(void)callParsing{

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

[self parseXMLFileAtURL:urlString];

[self performSelectorOnMainThread:@selector(droppingPin) withObject:nil waitUntilDone:YES];

[pool drain];

}

The above code is working fine, but once i changed the mapview, the appllication get crashed. Anyone can help me to fix the issue?

thanks in advance.

A: 

urlString is already autoreleased when it is returned from stringWithFormat. Since you are using urlString in callParsing which is executed on a different thread, you should pass it as an object to that method. Otherwise you risk it getting released before the callParsing method is executed and thus causing the crash:

...
[self performSelectorInBackground:@selector(callParsing:) withObject:urlString];
...

-(void)callParsing:(NSString*)urlString {
...
Claus Broch