核心数据,NSFetchResultsController泄漏

时间:2010-06-25 23:19:47

标签: iphone objective-c xcode core-data memory-leaks

我不确定泄漏是在我的实施中还是来自苹果方面......

仪器告诉我,这行中有泄漏:

  

if(![[self fetchedResultsController]   performFetch:安培;错误])

我通过将fetchController读取到Map来添加注释....就像这样:

-(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;
            }
        }
    }



}

我初始化我的FetchController,如下所示:

- (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;
}    

我在Navigate Back后立即泄漏,ViewController获取Deallocated,我释放了我的fetch控制器对象。

我的sqlite DB中的记录数量周围泄漏的对象数量很多(我猜的类型相同)

先谢谢你的帮助....

1 个答案:

答案 0 :(得分:1)

如上所述,泄漏可能在您的AddAnnotation类中。