views:

47

answers:

1

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?

+1  A: 

What is colorNum? Could it ever be some crazy value outsides the array's bounds?

Is palette a 'retain' property... the palette object really has been retained, right? Is it synthesized, or have you implemented your own getPalette method?

Graham Perks
Hi Graham, indeed-- I found some advice elsewhere on stackoverflow to turn on “Stop on Objective-C Exceptions” in Xcode's Run menu, and it's an index out of bounds as you suggested, something I had assumed would have crashed it. I am surprised that Xcode doesn't always crash on index out of bounds.... maybe because it was only one over and it was referencing nil?
juggleware