0

On a background thread checking for intersections I was leaking a large amount of memory. I tracked down where the leak was occurring and it was due to fast enumeration. I tried using an @autorelease but that did not fix it either. What ended up fixing the leak was just using normal iteration, and I have no idea why.

background thread created using dispatch_async, running on ipad mini 2 ios8

 // shapes is a NSMutable array
for (RTShape *shape in shapes){
     // ... intersection code
}

results in a memory leak, with this fixing it

for (int i = 0; i < shapes.count; i++){
    RTShape *shape = [shapes objectAtIndex: i]; 
    // ... same intersection code 
}

Does anyone know why this causes a leak?

  • 1
    I don't see anything in the code provided to cause a leak. Either a false positive, optimization/debug issue or you have code in there that causes the leak. – Léo Natan Mar 09 '15 at 00:54
  • Are you somehow modifying the `shapes` array while enumerating it? – Hot Licks Mar 09 '15 at 00:56
  • I will bet anyone any amount that the "memory leak" is the temporary additional retain caused by the fast enumeration changing the lifecycle slightly and not any sort of memory leak at all. – Tommy Mar 09 '15 at 00:59

0 Answers0