2
只是一個快速的內存管理問題,如果我可能...是否代碼低於確定,或者我應該做一個保留和autorelease,我覺得我應該。但根據規則unarchiveObjectWithFile
不包含new
,copy
或alloc
。unarchiveObjectWithFile保留/ autorelease需要?
-(NSMutableArray *)loadGame {
if([[NSFileManager defaultManager] fileExistsAtPath:[self pathForFile:@"gameData.plist"]]) {
NSMutableArray *loadedGame = [NSKeyedUnarchiver unarchiveObjectWithFile:[self pathForFile:@"gameData.plist"]];
return loadedGame;
} else return nil;
}
或
-(NSMutableArray *)loadGame {
if([[NSFileManager defaultManager] fileExistsAtPath:[self pathForFile:@"gameData.plist"]]) {
NSMutableArray *loadedGame = [[NSKeyedUnarchiver unarchiveObjectWithFile:[self pathForFile:@"gameData.plist"]] retain];
return [loadedGame autorelease];
} else return nil;
}
非常感謝尼克,也感謝您對格式正確的指針。非常感激。 – fuzzygoat 2010-04-19 11:05:06