BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.24k stars 4.61k forks source link

Memory is Not Decreasing after Applying Filters #2576

Open sohilspaceo opened 6 years ago

sohilspaceo commented 6 years ago

I am using five Filters at a time on a UIImage and once it's completed I am de-allocting all the objects but still memory is increasing if I apply filter to next UIImage.

@autoreleasepool {
        GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:faxImage];
        GPUImageSaturationFilter *saturationFilter = [[GPUImageSaturationFilter alloc]init];
        [saturationFilter setSaturation:0];
        [stillImageSource addTarget:saturationFilter];
        [stillImageSource processImage];
        [saturationFilter useNextFrameForImageCapture];
        UIImage *copyImage=[saturationFilter imageFromCurrentFramebuffer];
        stillImageSource=[[GPUImagePicture alloc] initWithImage:copyImage];
        GPUImagePicture *copyGPUimage = [[GPUImagePicture alloc] initWithImage:copyImage];

        GPUImageColorInvertFilter *invertFilter=[[GPUImageColorInvertFilter alloc]init];
        [copyGPUimage addTarget:invertFilter];
        [copyGPUimage processImage];
        [invertFilter useNextFrameForImageCapture];
        UIImage *imgTempr=[invertFilter imageFromCurrentFramebuffer];
        copyGPUimage= [[GPUImagePicture alloc]initWithImage:imgTempr];

        GPUImageGaussianBlurFilter *gaussianBlur=[[GPUImageGaussianBlurFilter alloc]init];
        [gaussianBlur setBlurRadiusInPixels:5.0];
        [copyGPUimage addTarget:gaussianBlur];
        [copyGPUimage processImage];
        [gaussianBlur useNextFrameForImageCapture];

        UIImage *imgTempa=[gaussianBlur imageFromCurrentFramebuffer];
        copyGPUimage= [[GPUImagePicture alloc]initWithImage:imgTempa];

        GPUImageColorDodgeBlendFilter *colorDodge=[[GPUImageColorDodgeBlendFilter alloc]init];
        [stillImageSource addTarget:colorDodge];
        [copyGPUimage addTarget:colorDodge];
        [stillImageSource processImage];
        [copyGPUimage processImage];
        [colorDodge useNextFrameForImageCapture];
        UIImage *imageWithAppliedThreshold=[colorDodge imageFromCurrentFramebuffer];
        stillImageSource = [[GPUImagePicture alloc] initWithImage:imageWithAppliedThreshold];
        GPUImageMonochromeFilter *monochromeFilter=[[GPUImageMonochromeFilter alloc]init];
        [monochromeFilter setIntensity:0.75];
        [monochromeFilter setColorRed:0.0 green:0.0 blue:0.0];
        [monochromeFilter setBackgroundColorRed:1.0 green:1.0 blue:1.0 alpha:1.0];
        [stillImageSource addTarget: monochromeFilter];
        [stillImageSource processImage];
        [monochromeFilter useNextFrameForImageCapture];
        imageWithAppliedThreshold=[monochromeFilter imageFromCurrentFramebuffer];

        stillImageSource = nil;
        saturationFilter = nil;
        copyGPUimage = nil;
        invertFilter = nil;
        gaussianBlur = nil;
        colorDodge = nil;
        monochromeFilter = nil;
        return imageWithAppliedThreshold;
    }

Tried many solution but no luck. The max memory goes to 1 GB on iPhone 6s Plus, if I apply filters to 10 UIImages at a time.

Besides, above solution I also tried removeTargets and removeOutputFrameBuffer but no luck. Please guide me I need the filters but memory should not increse by 100 MB.

godlikezjy commented 5 years ago

我也遇到了同样的问题,capturePhotoAsImageProcessedUpToFilter后内存升高了好多

xiaotong33 commented 2 years ago

后来怎么解决的呢?,我也遇见了