释放目标C中的对象

Ere*_*eka 0 memory-management objective-c ios

我只需要一些关于内存管理的帮助.我在屏幕上显示大约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);
}
Run Code Online (Sandbox Code Playgroud)

Sea*_*ell 5

这种方法似乎正在泄漏UIImageView您在第二行创建的内容.你alloc没有相应的releaseautorelease.我说"出现"因为我怀疑你没有包含所有的方法(你没有向我们展示任何与你的UIImageView做任何事情的代码......).

您对各种CGRef的管理都很好.