是的,我知道我應該閱讀更多關於內存管理,試圖找到和理解,但我仍然沒有真正知道爲什麼當我釋放NSMutableArray(見代碼)這段代碼崩潰。我最初做了alloc/init。內存管理只是好奇
- (void)readSelectedPlayers {
//Prepare File Manager
NSString *filePath = [self dataFilePath];
NSFileManager *fileMgr;
fileMgr = [NSFileManager defaultManager];
//
NSMutableArray *theObjects = [[NSMutableArray alloc] initWithCapacity:0];
NSMutableArray *activePlayersArray = [[NSMutableArray alloc] initWithCapacity:0];
NSMutableArray *readyPlayers = [[NSMutableArray alloc] initWithCapacity:0];
//
// Select all keys from the plist
NSMutableDictionary *playerDict = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
NSArray *allMyKeys = [playerDict allKeys];
//
for(NSString * myKey in allMyKeys) {
theObjects = [playerDict valueForKey:myKey];
if ([[theObjects objectAtIndex:1] intValue] == YES) {
[activePlayersArray addObject:myKey];
}
}
NSLog(@"activePlayersArray: %@", activePlayersArray);
//
//========CALL AccesQuestionDB MODULE TO SHUFFLE PLAYERS=========//
AccessQuestionsDB *shufflePlayersFunction = [AccessQuestionsDB new];
readyPlayers = [shufflePlayersFunction shufflePlayers: activePlayersArray];
NSLog(@"readyPlayers: %@", readyPlayers);
//
[readyPlayers release];
[theObjects release];
[activePlayersArray release];
}
的 '//' 字裏行間只是爲了獲得更好的在這裏格式的代碼。
一個大謝謝你,真的很感激。 – PeterK 2010-12-19 14:46:53