3

我查看了论坛以找到类似的问题,但似乎我的问题有所不同。我正在使用 GPUImage,我使用 bash 脚本构建了框架。我查看了创建过滤器及其处理链的示例。但在我的应用程序中,我面临着内存消耗的不断增加。没有内存泄漏,我分析了我的应用程序。

图像 - 是从相机拍摄的图像。我在 for 循环中调用下面描述的代码。在应用程序终止之后,我确实见证了内存从 7MB 增加到 150MB。

这是代码:

- (void)processImageInternal:(UIImage *)image
{
    GPUImagePicture * picture = [[GPUImagePicture alloc]initWithImage:image];

    GPUImageLanczosResamplingFilter *lanczosResamplingFilter = [GPUImageLanczosResamplingFilter new];

    CGFloat scale = image.scale;
    CGSize size = image.size;
    CGFloat newScale = roundf(2*scale);
    CGSize newSize = CGSizeMake((size.width *scale)/newScale,(size.height *scale)/newScale);

    [lanczosResamplingFilter forceProcessingAtSize:newSize];

    [picture addTarget:lanczosResamplingFilter];

    GPUImageGrayscaleFilter * grayScaleFilter = [GPUImageGrayscaleFilter new];
    [grayScaleFilter forceProcessingAtSize:newSize];

    [lanczosResamplingFilter addTarget:grayScaleFilter];

    GPUImageMedianFilter * medianFilter = [GPUImageMedianFilter new];
    [medianFilter forceProcessingAtSize:newSize];

    [grayScaleFilter addTarget:medianFilter];

    GPUImageSharpenFilter * sharpenFilter  = [GPUImageSharpenFilter new];
    sharpenFilter.sharpness +=2.0;
    [sharpenFilter forceProcessingAtSize:newSize];

    [medianFilter addTarget:sharpenFilter];

    GPUImageGaussianBlurFilter * blurFilter = [GPUImageGaussianBlurFilter new];
    blurFilter.blurSize = 0.5;
    [blurFilter forceProcessingAtSize:newSize];

    [sharpenFilter addTarget:blurFilter];

    GPUImageUnsharpMaskFilter * unsharpMask = [GPUImageUnsharpMaskFilter new];
    [unsharpMask forceProcessingAtSize:newSize];

    [blurFilter addTarget:unsharpMask];

    [picture processImage];

    image = [unsharpMask imageFromCurrentlyProcessedOutput];
 }

代码在后台线程中执行。

这是调用代码:

for (NSUInteger i=0;i <100;i++)
{
    NSLog(@" INDEX OF I : %d",i);
    [self processImageInternal:image];
}

我什至在方法中添加了一些清理逻辑- (void)processImageInternal:(UIImage *)image- (void)processImageInternal:(UIImage *)image { ......... [picture processImage];

   image = [unsharpMask imageFromCurrentlyProcessedOutput];

  //clean up code....

  [picture removeAllTargets];

    [self releaseResourcesForGPUOutput:unsharpMask];
    [self releaseResourcesForGPUOutput:blurFilter];
    [self releaseResourcesForGPUOutput:sharpenFilter];
    [self releaseResourcesForGPUOutput:medianFilter];
    [self releaseResourcesForGPUOutput:lanczosResamplingFilter];
    [self releaseResourcesForGPUOutput:grayScaleFilter];

在发布方法中,基本上我会发布任何可能发布的内容:FBO、纹理、目标。这是代码:

- (void)releaseResourcesForGPUOutput:(GPUImageOutput *) output
{
  if ([output isKindOfClass:[GPUImageFilterGroup class]])
  {
    GPUImageFilterGroup *group = (GPUImageFilterGroup *) output;

    for (NSUInteger i=0; i<group.filterCount;i++)
    {
        GPUImageFilter *  curFilter = (GPUImageFilter * )[group filterAtIndex:i];

        [self releaseResourcesForGPUFilter:curFilter];
    }
    [group removeAllTargets];
  }
  else if ([output isKindOfClass:[GPUImageFilter class]])
  {
    [self releaseResourcesForGPUFilter:(GPUImageFilter *)output];
  }
}

Unsharp mask it GPU 组过滤器,即过滤器的组合。

- (void)releaseResourcesForGPUFilter:(GPUImageFilter *)filter
{
  if ([filter respondsToSelector:@selector(releaseInputTexturesIfNeeded)])
  {
    [filter releaseInputTexturesIfNeeded];
    [filter destroyFilterFBO];
    [filter cleanupOutputImage];
    [filter deleteOutputTexture];
    [filter removeAllTargets];
  }
}

我按照布拉德的建议做了:我的代码在 UI 触摸处理循环中被调用。自动实现的池对象已耗尽,但从分配工具我看不到任何奇怪的东西。但是我的申请被终止了。最后总分配为 130 MB,但由于某些原因,我的应用程序被终止。这是它的样子:(我放置了屏幕截图,来自设备的日志,甚至来自 Instruments 的跟踪)。我的应用程序名为 TesseractSample,但我完全关闭了 tesseract 的使用,甚至是它的初始化。

http://goo.gl/w5XrVb

在来自设备的日志中,我看到使用了最大允许 rpages:

http://goo.gl/ImG2Wt

但我不知道这意味着什么。rpages == 最近最大(167601)

4

0 回答 0