memory leak zooming to geolocator result

666
3
09-28-2011 01:38 PM
SeychellesMartinez
New Contributor
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];
 }
}
0 Kudos
3 Replies
EddieJesinsky
New Contributor
I believe that using [addressCandidate.attributes mutableCopy] is like using alloc, so you need to release that copy as well.

NSDictionary *atts = [addressCandidate.attributes mutableCopy];
//use it
[atts release];
0 Kudos
NimeshJarecha
Esri Regular Contributor
Since you are taking the mutableCopy, you own it and must release it. The following should work.

[addressCandidate.attributes mutableCopy]autorelease]


Regards,
Nimesh
0 Kudos
SeychellesMartinez
New Contributor
That was it. Thank you!
0 Kudos