I have a method getImageData which I call as [self performSelectorInBackground:@selector(getImagesData ) withObject:nil]; in my viewDidLoad. getImageData has a for-loop i realised that each index in the loop is called more than once. I also access a static NSMutableArray in the loop. When i don't retain the array it gives me exc bad access. If I retain it the loop runs endlessly
views:
102answers:
1
A:
Sounds like a concurrency issue (and, furthermore, that you aren't really addressing the problem by understanding it -- I would suggest reading the Cocoa Memory Management Guide [same as iPhone] and one of the Concurrency Guides provided in the documentation).
Specifically, might you be calling -performSelectorInBackground: twice?
A for loop won't magically re-visit indices without their being something in your code that is:
- changing the loop invariant
- corrupting memory in exactly the right way
- you are inadvertently executing the loop multiple times -
If I retain it the loop runs endlessly indicates that you are doing 3. That it crashes otherwise is just because you aren't managing memory correctly; it is a symptom of a different problem.
bbum
2009-08-21 17:41:56