0

画像に 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];

誰かが同じ問題を経験した場合は、提案してください。ありがとう

4

1 に答える 1

1

ARC を使用していないため、いくつかの場所でメモリ リークが発生しているようです。以前に値をリリースせずに継続的に割り当てを行うと、リークが発生します。これは、メモリ管理に関する優れた記事です。https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html

注釈を付けたスポットが適切に解放されていることを確認してから、もう一度確認してください。追加する 15 個のフィルターのそれぞれに 2 つの潜在的なリーク スポットがある場合、30 個のリークが発生する可能性があります。

編集: 2 つの潜在的な修正も追加しましたが、メモリを適切に管理して、他の場所に問題がないことを確認してください。

//--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];
于 2012-12-24T15:49:59.380 に答える