我只需要一些关于内存管理的帮助。我在屏幕上显示大约 500 帧。我的应用程序似乎在模拟器上运行良好,但在 iPad 上它在显示大约 450 帧后崩溃。问题似乎是由于内存不足。下面是我的代码的一部分。我是正确释放对象还是需要做更多的事情?
- (void)drawBufferWidth:(int)width height:(int)height pixels:(unsigned char*)pixels
{
CGRect rect = CGRectInset(self.view.bounds, 0.0, 0.0);
UIImageView *img = [[UIImageView alloc] initWithFrame:rect];
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef gtx = CGBitmapContextCreate(pixels, width, height, BitsPerComponent, BytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);
CGImageRef myimage = CGBitmapContextCreateImage(gtx);
img.image = [UIImage imageWithCGImage:myimage];
CGContextRelease(gtx);
CGImageRelease(myimage);
CGColorSpaceRelease(colorSpace);
}