views:

41

answers:

1

Hi, I am not sure if the leak is in my implementation or is it from apple's side....

Instruments indicate me that I have a leak in this line :

if (![[self fetchedResultsController] performFetch:&error])

I am adding annotations by reading the fetchController to the Map.... like this :

-(void)fillMapWithAnnotations{

    NSError *error = nil;
    if (![[self fetchedResultsController] performFetch:&error]) {

        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }   


    for(int a=0; a<[[[fetchedResultsController sections]objectAtIndex:0] numberOfObjects]; a++){

        LookAround *look=(LookAround *)[fetchedResultsController objectAtIndexPath:[NSIndexPath indexPathForRow:a inSection:0]];
        if(look){
            AddAnnotation *newAnnotation=[[AddAnnotation alloc]initWithLookAround:look];    

            if(newAnnotation){
                [self.mapView addAnnotation:newAnnotation];
                [newAnnotation release];
                newAnnotation=nil;
            }
        }
    }



}

and I initialize my FetchController like this:

- (NSFetchedResultsController *)fetchedResultsController{
    // Set up the fetched results controller if needed.
    if (fetchedResultsController == nil) {
        // Create the fetch request for the entity.
        NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
        // Edit the entity name as appropriate.
        NSEntityDescription *entity = [NSEntityDescription entityForName:@"LookAround" inManagedObjectContext:managedObjectContext];
        [fetchRequest setEntity:entity];

        // Edit the sort key as appropriate.
        NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
        NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];

        [fetchRequest setSortDescriptors:sortDescriptors];

        // Edit the section name key path and cache name if appropriate.
        // nil for section name key path means "no sections".
        NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
        aFetchedResultsController.delegate = self;

        self.fetchedResultsController = aFetchedResultsController;

        [aFetchedResultsController release];
        [fetchRequest release];
        [sortDescriptor release];
        [sortDescriptors release];
    }

    return fetchedResultsController;
}    

I get a leak as soon as i Navigate Back, the ViewController gets Deallocated in which I release my fetch controller object.

The objects that leak are numerous (and of the same type I guess) around the number of records in my sqlite DB

Thanks in advance for your help....

+1  A: 

As I noted above, the leak is probably in your AddAnnotation class.

Run Loop