views:

160

answers:

1
BOOL continueLoop;
CGPoint thePoint; 

while(continueLoop != NO)
{
 continueLoop = NO;

 thePoint = [self generateRandomLocation];

 NSMutableArray *blocks = [self getBlocksForX:thePoint.x];

 for(BlueBlock *block in blocks)
 {
  if(block.getBlockLocationY == thePoint.y)
  {
   continueLoop = YES;
  }
 }
 [blocks release];
}

This causes a crash when ran in instruments but not in Xcode. I narrowed the problem down, it happens when this line of code is in a loop... NSMutableArray *blocks = [self getBlocksForX: thePoint.x]; the method returns a NSMutableArray, I store it in blocks each time the loop is executed then at the end of the loop I release it. What would be causing instruments to crash?

+3  A: 

since you never alloc, copy, or retain blocks you should not be releasing it.

It may help for errors like this to run the static analyzer.

cobbal
the method returns an allocated NSMutableArray
ACV
ah, usual convention is (from memory management programming guide) `You “create” an object using a method whose name begins with “alloc” or “new” or contains “copy”` http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/MemoryMgmt/Articles/mmObjectOwnership.html#//apple_ref/doc/uid/20000043-BEHDEDDB
cobbal
Okay, I'm still learning I'll remember that for the future.
ACV
I ran the Clang Static Analyzer and didn't find anything...
ACV
Sorry for triple post, I changed it from a while loop to a do while loop (tried everything else I could think of already)and problem solved.
ACV
the problem with the while loop is (maybe) that you don't initialize continueLoop
cobbal