I'm getting a bunch of memory leaks for this bit of code in Instruments.
Here:
NSArray *tmpCoords = [loc.mapCoords componentsSeparatedByString:@","];
and Here:
coords.tileRow = [NSString stringWithFormat:@"%d",x];
coords.tileCol = [NSString stringWithFormat:@"%d",y];
Is there a better way to do this? I'm basically parsing a string and adding stuff to an array. How do I clean this up?
Update: CoordinateArray is retained in .h and released in dealloc. Should have mentioned that earlier. Full Code:
-(void)loadCoordinates
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// get list of coordinates once
coordinateArray = [[NSMutableArray alloc] init];
MyAppDelegate *app = [[UIApplication sharedApplication] delegate];
MyData *myData = app.data;
NSArray *myArray = [myData locations];
for ( NSUInteger i = 0; i < [myArray count]; i++ )
{
LocationModel *loc = [myArray objectAtIndex:i];
NSArray *tmpCoords = [loc.mapCoords componentsSeparatedByString:@","];
if ([tmpCoords count] < 2 ) continue;
CoordinateModel *coords = [[CoordinateModel alloc] init];
coords.row = [tmpCoords objectAtIndex:0];
coords.col = [tmpCoords objectAtIndex:1];
NSString *xString = [tmpCoords objectAtIndex:0];
int x = [xString floatValue] / DEFAULT_TILE_SIZE;
NSString *yString = [tmpCoords objectAtIndex:1];
int y = [yString floatValue] / DEFAULT_TILE_SIZE;
coords.tileRow = [NSString stringWithFormat:@"%d",x];
coords.tileCol = [NSString stringWithFormat:@"%d",y];
[coordinateArray addObject:coords];
[coords release];
}
[pool release];
}