GPUImage memory warnings

百般思念 提交于 2019-12-08 11:28: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


回答1:


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

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.

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


来源:https://stackoverflow.com/questions/14022770/gpuimage-memory-warnings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!