Superdev
Superdev

Reputation: 562

GPUImage memory warnings

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

Upvotes: 0

Views: 2681

Answers (1)

propstm
propstm

Reputation: 3629

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

Upvotes: 1

Related Questions