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