gpt4 book ai didi

ios - GPUImage 内存警告

转载 作者:行者123 更新时间:2023-11-29 04:13:37 27 4
gpt4 key购买 nike

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

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

最佳答案

由于您没有使用 ARC,因此看起来您在多个地方泄漏了内存。通过在之前没有释放值(value)的情况下不断分配,您正在造成泄漏。这是一篇关于内存管理的好文章。 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];

关于ios - GPUImage 内存警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14022770/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com