English 中文(简体)
从数据库检索数据时的记忆泄漏
原标题:Memory leak when retrieving data from database

简而言之,I ve创建了数据库检索习惯方法:

+(NSArray*) recordsForTable:(NSString *)table predicate:(NSPredicate *)prd{
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

    NSEntityDescription *entity = [NSEntityDescription entityForName:table inManagedObjectContext:managedObjectContext];

    [fetchRequest setEntity:entity];

    [fetchRequest setPredicate:prd];

    NSArray *records = [managedObjectContext executeFetchRequest:fetchRequest error:nil];

    [fetchRequest release];

    return records;
}

i 然后在这种方法中使用上述方法:

-(NSArray *)tableViewControllerData{

    NSNumber *savedBool = [[NSNumber alloc] initWithBool:YES];

    NSString *onlyGetSavedVisitObjects = [NSString stringWithFormat:@"bolSaved=%@", savedBool];
    [savedBool release];
    NSMutableArray *data = [[[CoreDataAccess recordsForTable:@"LPVisit" stringPredicate:onlyGetSavedVisitObjects] mutableCopy] autorelease];
    NSSortDescriptor *dateDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"dteVisitDate" ascending:NO];
    NSArray *descriptors = [NSArray arrayWithObjects:dateDescriptor, nil];
    [data sortedArrayUsingDescriptors:descriptors];

    return data;    
}

问题在于,当用户改变LPVisit表格,并忆及这一方法显示这些变化时,它便会错失申请。

[EDIT]

其产生的例外是:

 -[__NSArrayM objectID]: unrecognized selector sent to instance 0x4dac1f0

我认为这一错误是行的:

NSMutableArray *data = [[[CoreDataAccess recordsForTable:@"LPVisit" stringPredicate:onlyGetSavedVisitObjects] mutableCopy] autorelease];

如果我去掉自动释放,我就会发现一个记忆泄露,但申请确实发生故障。

是否有任何人事先了解情况

问题回答

Is it possible that the mutable copying is throwing the exception because *records is nil? This might happen if @"bolSaved=%@" is a typo and should be @"boolSaved=%@".





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签