【发布时间】:2011-08-07 11:26:50
【问题描述】:
我对此很陌生,并且似乎在这段代码中有一个我无法修复的泄漏:
仪器以 100% 显示在此行:
NSMutableArray *read_Question = [[NSMutableArray alloc] initWithCapacity: 0];
我尝试了各种方法,但都无法解决。
有好心人可以建议我如何进行吗?
- (NSMutableArray *)readQuestion: (int)questionNr {
NSMutableArray *read_Question = [[NSMutableArray alloc] initWithCapacity: 0];
NSError *error;
//=========PREPARE CORE DATA DB===========//
if (managedObjectContext == nil) {
managedObjectContext = [(FamQuiz_R0_1AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; }
// Define qContext
NSManagedObjectContext *qContext = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"questions" inManagedObjectContext:qContext];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [qContext executeFetchRequest:fetchRequest error:&error];
for (NSManagedObject *info in fetchedObjects) {
if ([[info valueForKey:@"idQ"] intValue] == questionNr) {
[read_Question addObject:[info valueForKey:@"question"]];
[read_Question addObject:[info valueForKey:@"qRightAnswer"]];
[read_Question addObject:[info valueForKey:@"qWrongAnswer1"]];
[read_Question addObject:[info valueForKey:@"qWrongAnswer2"]];
}
}
[fetchRequest release];
return [read_Question autorelease];
}
【问题讨论】:
-
仪器显示什么?有什么具体点吗?
-
显然您将 managedObjectContext 定义为标题中的属性。属性是如何定义的?
-
仪器显示 NSMutableArray *read_Question = [[NSMutableArray alloc] initWithCapacity: 0];
-
这样:NSManagedObjectContext *managedObjectContext;
-
我的意思是:它是用retain定义的吗,属性是什么?
标签: iphone cocoa-touch memory-leaks