CGBitmapContextCreate no iPhone / iPad

Eu tenho um método que precisa analisar um monte de imagens PNG grandes pixel por pixel (os PNGs são 600x600 pixels cada). Parece funcionar muito bem no simulador, mas no dispositivo (iPad), recebo um EXC_BAD_ACCESS em alguma função de cópia da memória interna. Parece que o tamanho é o culpado, porque se eu tentar em imagens menores, tudo parece funcionar. Aqui está a carne relacionada à memória do método abaixo.

+ (CGRect) getAlphaBoundsForUImage: (UIImage*) image 
{    
    CGImageRef imageRef = [image CGImage];

NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

unsigned char *rawData = malloc(height * width * 4);
memset(rawData,0,height * width * 4);

NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);

CGColorSpaceRelease(colorSpace);

CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
CGContextRelease(context);

/* non-memory related stuff */

free(rawData);

Quando executo isso em um monte de imagens, ele é executado 12 vezes e depois sai, enquanto no simulador ele não executa nenhum problema. Vocês têm alguma idéia?

questionAnswers(7)

yourAnswerToTheQuestion