Instruments is informing me that I am leaking memory from the following code snippet
for (int x=0; x<20; x++)
{
LeagueTableRow *aLTR = [[LeagueTableRow alloc] init]; //leaks a certain percentage here
match = [substring rangeOfString: @"text team large-link"];
if (match.location == NSNotFound)
{
}
if ((match.location + match.length) > ([substring length]))
{
}
substring = [substring substringFromIndex:(match.location + match.length)];
match2 = [substring rangeOfString: @"title="];
substring = [substring substringFromIndex:(match2.location + match2.length+1)];
match2 = [substring rangeOfString: @">"];
aLTR.teamName = [substring substringToIndex:match2.location-1]; //leaks a percentage here
match2 = [substring rangeOfString: @"number total mp"];
substring = [substring substringFromIndex:(match2.location + match2.length+1)];
match = [substring rangeOfString: @">"];
match2 = [substring rangeOfString: @"<"];
aLTR.played = [substring substringWithRange:NSMakeRange(match.location+1, (match2.location-(match.location+1)))]; //leaks a percentage here
[self.theLeagueTableArray addObject:aLTR];
[aLTR release];
}
The instruments informs me of the leak and where I commented the code saying there is a leak it says that this line is a cause of a certain percentage of the leak.
The LeagueTableRow class is a very simple container class and each of the vars in it are released at the dealloc for the class.
What could be the issue here?
I alloc aLTR at the start of the loop and then release aLTR at the end of the loop.
The NSString methods are all autorelease on the returned strings AFAIK so the code seems tight.
Anybody able to shed some light on this confusing situation ? The build and analyze tool doesnt mention any issues here either.
Many Thanks,
-Code
if the backing instnce variable for this
theLeagueTableArrayis never released, neither will any of the league table rows in it. Check your dealloc method for this class and make sure the variable is released there.