GPUImage内存警告 [英] GPUImage memory warnings

查看:235
本文介绍了GPUImage内存警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在图像上应用GPUImage滤镜时遇到一个奇怪的问题.我正在尝试在图像上应用不同的滤镜,但是在应用10-15个滤镜后,它会给我内存警告,然后崩溃. 这是代码:

I am facing a strange problem while applying GPUImage Filters on image. I am trying to apply different filters on an image but after applying 10-15 filters it gives me memory warning and then crashes. Here is the code:

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];

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

If anyone gone through the same problem please suggest. Thanks

推荐答案

由于您没有使用ARC,因此看起来好像您在多个地方泄漏了内存.通过连续分配而不事先释放该值,就可以创建泄漏.这是一篇有关内存管理的好文章. https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html

Since you are not using ARC it looks like you are leaking memory in several places. By continually allocing without previously having released the value you are creating your leaks. Here is a good article on memory management. https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html

检查以确保正确注释了我注释的那些点,然后再次检查,如果要添加的15个过滤器中的每个都有两个潜在的泄漏点,则将创建30个泄漏点.

Check to make sure those spots I've annotated are being properly released, then check again, you are creating what could be 30 leaks if you have two potential leak spots for each of the 15 filters you are adding.

我还为您添加了两个潜在的修复程序,但请确保您正确地管理内存以确保在其他地方没有任何问题.

I've also added two potential fixes for you, but make sure you are properly managing your memory to make sure you don't have any issues elsewhere.

//--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];

这篇关于GPUImage内存警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆