请问为什么我的代码会出现内存泄漏?
我已在代码中的分析器中添加了注释。如果有人能帮忙解决问题并解释一下为什么会出现这两个注释,我将不胜感激。
- (void)viewDidDisappear:(BOOL)animated {
// Empty array to be sure it is empty
[playerArray removeAllObjects];
//============CLEAN OUT DOUBLE NAMES FROM ARRAY==============//
NSArray *sortedDummyArray = [[NSArray alloc] initWithArray:selectedPlayersArray];
////>>>>The line above is line 84<<<<<<<////
// Sort the array
sortedDummyArray = [sortedDummyArray sortedArrayUsingSelector:@selector(compare:)];
NSMutableArray *finalArray = [[NSMutableArray alloc]initWithArray:sortedDummyArray];
////>>>>>> Possible memory leak on line 84 <<<<<<<<////
int xx = [sortedDummyArray count];
int yy;
int counter = 0;
int rr = 0;
for (int oo = 0; oo < xx; oo++) {
yy = [finalArray count];
for (int zz = 0; zz < yy; zz++) {
// If hit, clean out the double name
if ([[sortedDummyArray objectAtIndex:oo] isEqualToString:[finalArray objectAtIndex:rr]]) {
counter++;
// Check if there is more than one of this name
if (counter > 1) {
[finalArray removeObjectAtIndex:rr];
rr--;
counter--;
}
}
rr++;
}
counter = 0;
rr = 0;
}
[sortedDummyArray retain];
// Save who is in the game
AccessQuestionsDB *shufflePlayersFunction = [AccessQuestionsDB new];
finalArray = [shufflePlayersFunction shufflePlayers: finalArray];
[shufflePlayersFunction release];
TempPlayersInTheGame *savePlayersInTheGame = [TempPlayersInTheGame new];
[savePlayersInTheGame saveSelectedPlayers:finalArray];
[savePlayersInTheGame release];
[finalArray release]; //>>>> see comment below
////>>>>>Incorrect decrement of the reference count of an object that is not owned at this point by the caller <<<<<</////
[sortedDummyArray release];
[super viewDidDisappear:animated];
}