Note that there are some explanatory texts on larger screens.

plurals
  1. POLeaks on componentsSeparatedByString and stringWithFormat, is there a better way to do this?
    text
    copied!<p>I'm getting a bunch of memory leaks for this bit of code in Instruments.</p> <p>Here:</p> <pre><code>NSArray *tmpCoords = [loc.mapCoords componentsSeparatedByString:@","]; </code></pre> <p>and Here:</p> <pre><code> coords.tileRow = [NSString stringWithFormat:@"%d",x]; coords.tileCol = [NSString stringWithFormat:@"%d",y]; </code></pre> <p>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?</p> <p>Update: CoordinateArray is retained in .h and released in dealloc. Should have mentioned that earlier. Full Code:</p> <pre><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 &lt; [myArray count]; i++ ) { LocationModel *loc = [myArray objectAtIndex:i]; NSArray *tmpCoords = [loc.mapCoords componentsSeparatedByString:@","]; if ([tmpCoords count] &lt; 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]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload