【发布时间】:2011-10-10 10:23:14
【问题描述】:
我目前正在开发一个进展良好的 iOS 项目,但整个内存问题 在 iOS 上无法正常工作。
iphone 相机记录一个流。我有一个通过队列执行的捕获方法。 相机图像被转换为灰度。它运作良好,但一段时间后给出了一些 内存警告并关闭应用程序,因为它的内存不足。
我发现了这里的错误源
CGColorSpaceRef colorSpaceGray = CGColorSpaceCreateDeviceGray();
CGContextRef newContextGray = CGBitmapContextCreate(baseAddressGray, width, height, 8, width, colorSpaceGray, kCGImageAlphaNone);
CGImageRef GrayImage = CGBitmapContextCreateImage(newContextGray);
UIImage *img= [UIImage imageWithCGImage:GrayImage scale:1.0 orientation:UIImageOrientationRight];
[self.imageView performSelectorOnMainThread:@selector(setImage:) withObject:img waitUntilDone:NO];
free(baseAddressGray);
CGColorSpaceRelease(colorSpaceGray);
CGContextRelease(newContextGray);
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
所有内容都位于一个自动释放池中,该池随后会被排出。 作为崩溃源的行是
CGContextRef newContextGray = CGBitmapContextCreate(baseAddressGray, width, height, 8, width, colorSpaceGray, kCGImageAlphaNone);
据我了解,这里应该没有内存问题,因为
CGColorSpaceRelease(colorSpaceGray);
CGContextRelease(newContextGray);
被释放。
我在这里做错了什么,或者缺少什么?
【问题讨论】:
标签: xcode memory-leaks