0

在图像上应用 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];

如果有人遇到同样的问题,请提出建议。谢谢

4

1 回答 1

1

由于您没有使用 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];
于 2012-12-24T15:49:59.380 回答