I have a loop where I'd like to redefine the contents of an array with every iteration. I'm worried about leaks. Is there anything wrong with this code?
for (int i=0;i<numberOfReps;i++){
NSArray *shuffledArray=[self shuffleArray:originalArray];
// use shuffled array
}
Thanks for reading!
EDIT:
Here is shuffleArray (credit to Kristopher Johnson from What's the Best Way to Shuffle an NSMutableArray?):
-(NSArray*)shuffleArray:(NSArray*)array{
NSMutableArray *newArray=[NSMutableArray arrayWithArray:array];
NSUInteger count = [newArray count];
for (NSUInteger i = 0; i < count; ++i) {
// Select a random element between i and end of array to swap with.
int nElements = count - i;
int n = (arc4random() % nElements) + i;
[newArray exchangeObjectAtIndex:i withObjectAtIndex:n];
}
return [NSArray arrayWithArray:newArray];
}
(And I am using ARC.)