Objective-c – iPhone Dev: big png sequences cause crash

cocoa-touchiphoneobjective c

I'm building an app which includes a number of image sequences (5 sequences with about 80 images each). It runs nicely in the iPhone simulator, but causes my iPhone to reboot when I test it. By the way, each png image is about 8k in size.
Has anyone successfully built a similar app?
Am I using too many resources for the iPhone to handle?
Anyone?

UPDATE:
Thanks to all for you answers! I've modified my code to use [UIImage imageWithContentsOfFile:] instead of [UIImage imageNamed:]
However I'm still unable to prevent the app from crashing my iPhone.
(please note that my pngs are not that big about 400x400px / 8k)

Does anyone have any suggestions?

Here's my code:

    // code snippet:
    myFrames = [[NSMutableArray alloc] initWithCapacity:maxFrames];
            NSMutableString *curFrame;
            num = 0;
    // loop (maxframes = 80)
            for(int f = 1; f < maxFrames+1; f++)
            {
                curFrame = [NSMutableString stringWithString:tName];

                if(f < 10) [curFrame appendString:[NSString stringWithFormat:@"00%i",f]]; 
                else if(f>9 && f<100) [curFrame appendString:[NSString stringWithFormat:@"0%i",f]]; 
                else [curFrame appendString:[NSString stringWithFormat:@"%i",f]]; 

                UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:curFrame ofType:@"png"]];

                if(img) [myFrames addObject:img];
                [img release];
            }
// animate the images!
            self.animationImages = myFrames;
            self.animationDuration = (maxFrames * .05); // Seconds
            [self startAnimating];

Best Answer

The best way to find out is to run the application under Instruments using Leaks or Object Alloc. If you see an upward trend that keeps rising, you might have a leak.

If you're using [UIImage imageNamed:], you should be aware that it pre-caches an optimized version which takes up more memory when compared with [UIImage imageWithContentsOfFile:]. Additionally, until iPhone 3.0, the cache created by [UIImage imageNamed:] doesn't get released when there's a memory warning.

The current-gen iPhone only has 128MB of ram, some of which is used by the OS itself. A 320x480 image fully uncompressed with an alpha channel can take 614k. If you have 400 unique images that are full screen, that's well over 128MB of ram, assuming it is loaded up and cached uncompressed.