seycho1981

memory leak zooming to geolocator result

Discussion created by seycho1981 on Sep 28, 2011
Latest reply on Sep 29, 2011 by seycho1981
Hi,

My app has a memory leak that I haven't been able to resolve. Instruments show the leak on the didFindLocationsForAddress method of the AGSLocatorDelegate. Can someone help me figuring out what is wrong in my code?

According to Instruments, the problem is when I'm using (on the code bellow):
:[addressCandidate.attributes mutableCopy]

- (void)locator:(AGSLocator *)locator operation:(NSOperation *)op didFindLocationsForAddress:(NSArray *)candidates
{
    //check and see if we didn't get any results
 if (candidates == nil || [candidates count] == 0)
 {
        //show alert if we didn't get results
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Results"
                                                        message:@"No Results Found By Locator"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        
        [alert show];
        [alert release];
 }
 else
 {

        AGSAddressCandidate *addressCandidate = (AGSAddressCandidate *)[candidates objectAtIndex:0];
        
        //get the location from the candidate
        AGSPoint *pt = addressCandidate.location;

        
        //create a marker symbol to use in our graphic
        AGSPictureMarkerSymbol *marker = [AGSPictureMarkerSymbol pictureMarkerSymbolWithImageNamed:@"BluePushpin.png"];
        marker.hotspot = CGPointMake(-9, -11);

        
        int levelToZoomTo = 4;
        AGSLOD* lod = [tiledMapServiceLayer.mapServiceInfo.tileInfo.lods objectAtIndex:levelToZoomTo];
        float zoomFactor = lod.resolution/self.mapView.resolution;
        AGSMutableEnvelope *newEnv =  
        [AGSMutableEnvelope envelopeWithXmin:self.mapView.envelope.xmin
                                        ymin:self.mapView.envelope.ymin 
                                        xmax:self.mapView.envelope.xmax 
                                        ymax:self.mapView.envelope.ymax
                            spatialReference:self.mapView.spatialReference];
        
        [newEnv expandByFactor:zoomFactor];
        [self.mapView zoomToEnvelope:newEnv animated:YES];

        
        //create the graphic
        AGSGraphic *graphic = [[AGSGraphic alloc] initWithGeometry: pt
                                                            symbol:marker 
                                                        attributes:[addressCandidate.attributes mutableCopy]
                                              infoTemplateDelegate:nil];
        
        
        //add the graphic to the graphics layer
        [self.graphicsLayer addGraphic:graphic];
        
        //release the graphic
        [graphic release];    
        
        NSLog(@"point %@", pt);
        
        //we have one result, center at that point
        [self.mapView centerAtPoint:pt animated:NO];
        
        [self.graphicsLayer dataChanged];
 }
}

Outcomes