Я получаю кучу утечек памяти для этого куска кода в Instruments.
Здесь:
NSArray *tmpCoords = [loc.mapCoords componentsSeparatedByString:@","];
и здесь:
coords.tileRow = [NSString stringWithFormat:@"%d",x];
coords.tileCol = [NSString stringWithFormat:@"%d",y];
IsЕсть ли лучший способ сделать это?Я в основном разбираю строку и добавляю материал в массив.Как мне это исправить?
Обновление: CoordinateArray сохраняется в .h и освобождается в dealloc.Должен был упомянуть, что раньше.Полный код:
-(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];
}