I'm working up a graphics effect for an iPhone app that simulates a low-res plasma effect from old demoscene days. I've got 600 squares on screen that are updating as fast as possible. Since I am using CoreGraphics (for now), I can get a very constant 11FPS with no freezing--
BUT when I try to add one simple NSArray lookup, the iPhone as well as the simulator freezes for several seconds every few seconds. I've run this in instruments and it says there is a leak -- the leak has to do with NSAutoReleasePool, but that doesn't really help. (I am creating an NSAutoReleasePool at the beginning of every update frame and draining the pool at the end.)
By process of elimination, I've been able to narrow it down to one line that's causing the slowdown. This line happens for each of the 600 block sprites each frame update:
//SLOOWWWNESS /LEAKING NSAUTORELEASEPOOL IS here (freezing every second or so)
UIColor *color = [palette objectAtIndex:colorNum];
//BUT DOESNT HAPPEN HERE... (works at full speed)
UIColor *color = [UIColor colorWithRed:0.25f green:0.25f blue:colorNum/15.0 alpha:1.0f];
... where palette is a NSArray property in the sprite, and contains a list of UIColor objects that I've created. This array of UIColor objects is created only once, when the app launches, and all sprites are using the same array.
Anyone have any ideas?