我開始在Instruments中測試我的應用程序以清除任何內存泄漏。我已經能夠清除所有與核心數據相關的內存泄漏。儀器總是指向我的這部分代碼:核心數據內存泄漏
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil) {
// Handle the error
}
我宣佈managedObjectContext與下面的代碼我的頭文件:
@interface UpperBody : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *upperTable;
NSMutableArray *exercises;
NSManagedObjectContext *managedObjectContext;
}
@property (nonatomic, retain) NSMutableArray *exercises;
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
我釋放managedObjectContext在(無效)dealloc的部分。這裏是使用managedObjectContext代碼的全部部分:
- (void)loadExercises {
if (managedObjectContext == nil) {
managedObjectContext = [(iFitAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
}
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Exercises" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"category == 1"];
[request setPredicate:predicate];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"exerciseName" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
[sortDescriptor release];
[sortDescriptors release];
NSError *error = nil;
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil) {
// Handle the error
}
[self setExercises:mutableFetchResults];
// [exercises addObject:@"Add Exercise"];
NSLog(@"Count of exercises %i", exercises.count);
[mutableFetchResults release];
[request release];
[self.tableView reloadData];
}
任何建議什麼可能會導致泄漏將不勝感激!先謝謝你!
你在'dealloc'方法中釋放'exercise'嗎? – albertamg
是的,我發佈了我的dealloc方法中的練習。 = /我不知道爲什麼樂器指向NSMutableArray * mutableFetchResults。我釋放managedObjectContext,結果和mutableFetchRequests。 –
儀器指向泄漏對象的分配位置,而不是泄漏位置。 – albertamg