在图像上应用GPUImage滤镜时,我遇到了一个奇怪的问题。我试图对图像应用不同的滤镜,但在应用了10-15个滤镜后,它给了我内存警告,然后崩溃了。代码如下:
sourcePicture = [[GPUImagePicture alloc] initWithImage:self.m_imageView.image smoothlyScaleOutput:YES];
GPUImageBrightnessFilter *bright=[[GPUImageBrightnessFilter alloc]init];
[bright setBrightness:0.4];
GPUImageFilter *sepiaFilter = bright;
[sepiaFilter prepareForImageCapture];
[sepiaFilter forceProcessingAtSize:CGSizeMake(640.0, 480.0)]; // This is now needed to make the filter run at the smaller output size
[sourcePicture addTarget:sepiaFilter];
[sourcePicture processImage];
UIImage *sep=[sepiaFilter imageFromCurrentlyProcessedOutputWithOrientation:3];
self.m_imageView.image=sep;
[sourcePicture removeAllTargets];如果有任何人遇到过同样的问题,请提出建议。谢谢
发布于 2012-12-24 23:49:59
由于您没有使用ARC,所以看起来您在几个地方泄漏了内存。通过不断分配而不释放之前的值,您正在创建您的泄漏。这里有一篇关于内存管理的好文章。https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html
检查以确保我已经注释的那些点被正确释放,然后再次检查,如果您正在添加的15个过滤器中的每一个都有两个潜在的漏点,那么您正在创建的可能是30个泄漏。
编辑:我还为你添加了两个潜在的修复,但请确保你正确管理你的内存,以确保你在其他地方没有任何问题。
//--Potentially leaking here--
sourcePicture = [[GPUImagePicture alloc] initWithImage:self.m_imageView.image smoothlyScaleOutput:YES];
//--This may be leaking--
GPUImageBrightnessFilter *bright=[[GPUImageBrightnessFilter alloc]init];
[bright setBrightness:0.4];
GPUImageFilter *sepiaFilter = bright;
//--Done using bright, release it;
[bright release];
[sepiaFilter prepareForImageCapture];
[sepiaFilter forceProcessingAtSize:CGSizeMake(640.0, 480.0)]; // This is now needed to make the filter run at the smaller output size
[sourcePicture addTarget:sepiaFilter];
[sourcePicture processImage];
UIImage *sep=[sepiaFilter imageFromCurrentlyProcessedOutputWithOrientation:3];
self.m_imageView.image=sep;
[sourcePicture removeAllTargets];
//--potential fix, release sourcePicture if we're done --
[sourcePicture release];https://stackoverflow.com/questions/14022770
复制相似问题