仪器检测到内存泄漏:
(Leaked Object= "__NSCFString")
这是我的代码:
-(NSArray*)loadAllPages{
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Page" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
initWithKey:@"date" ascending:YES];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
[sortDescriptor release];
NSError *error = nil;
myArray = [[NSArray alloc ]initWithArray:[[context executeFetchRequest:fetchRequest error:&error]autorelease]];
[fetchRequest release];
if (myArray == nil)
NSLog(@"%@",error);
return myArray;
}
指向泄漏的行是初始化myArray
。如果我不返回myArray
,则不会发生这种泄漏,所以这对我来说很奇怪。