0

我只需要一些关于内存管理的帮助。我在屏幕上显示大约 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);
}
4

1 回答 1

5

此方法似乎正在泄漏UIImageView您在第二行创建的内容。你有一个alloc没有对应的releaseor autorelease。我说“出现”是因为我怀疑您没有包含所有方法(您没有向我们展示任何对您的 UIImageView 执行任何操作的代码......)。

您对各种 CGRef 的管理很好。

于 2013-04-04T16:27:20.240 回答