【问题标题】:Core Data , NSFetchResultsController leaking核心数据,NSFetchResultsController 泄漏
【发布时间】:2010-06-25 23:19:46
【问题描述】:

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

仪器显示我在这一行有泄漏:

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

我通过将 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;
}    

当我导航返回时,我得到了一个泄漏,ViewController 被释放,我在其中释放了我的 fetch 控制器对象。

在我的 sqlite 数据库中的记录数附近,泄漏的对象很多(并且我猜是同一类型)

提前感谢您的帮助....

【问题讨论】:

  • 我猜泄漏是在你的 AddAnnotation 类中
  • 是的.. 我没有发布它的 iVar... 非常感谢
  • @JK - 您需要将评论移至答案,并且 jAmi 需要将其标记为已回答。否则,这个问题将永远显示为未回答。

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2011-09-19
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    • 2015-11-05
    • 2011-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多