我正在使用GPU图像开源框架来实现图像效果。问题是,当我尝试在图像上定期应用过滤器时,应用程序会给我一个内存警告然后崩溃。
以下是代码:
sourcePicture = [[GPUImagePicture alloc] initWithImage:[self scaleAndRotateImage:sourceImage] smoothlyScaleOutput:YES];
GPUImageGaussianBlurFilter *bright=[[GPUImageGaussianBlurFilter alloc]init];
[bright setBlurSize:1.0];
GPUImageFilter *sepiaFilter = bright;
[bright release];
[sepiaFilter prepareForImageCapture];
[sepiaFilter forceProcessingAtSize:self.m_imageView.image.size]; // This is now needed to make the filter run at the smaller output size
[sourcePicture addTarget:sepiaFilter];
[sourcePicture processImage];
UIImage *sep=[sepiaFilter imageFromCurrentlyProcessedOutput];
self.m_imageView.image=sep;
[sourcePicture release];
[sepiaFilter release];
请帮我摆脱这个问题。感谢
答案 0 :(得分:0)
sepiaFilter
未保留bright
,因此它只是指向已发布对象的指针。您应该更改它以保留对象。
GPUImageFilter *sepiaFilter = [bright retain]; // Now retain count is increased +1
否则这就是该对象发生的事情。
GPUImageGaussianBlurFilter *bright = [[GPUImageGaussianBlurFilter alloc] init]; // New object with retain count 1
[bright setBlurSize:1.0];
GPUImageFilter *sepiaFilter = bright; // Still retain count 1 (not being retained)
[bright release]; // Being released. Retain count = 0.
// At this point both sephiaFilter and bright point to released memory.
[sepiaFilter prepareForImageCapture]; // This is calling messages on a released object.
[sepiaFilter forceProcessingAtSize:self.m_imageView.image.size]; // This is calling messages on a released object.
[sourcePicture addTarget:sepiaFilter]; // This is passing a released object as an argument.