我们的应用程序使用GPUImage Framework来处理图像。我们在框架中使用几乎所有过滤器和混合模式。我们正在分配和释放内存。但是,尽管我们的“实时”内存大约保持在2.5MB左右,有时会增加到10MB但却又回落到2.5MB,这个应用程序毫无疑问会在保存大约13张使用覆盖或边框的图像后崩溃。因此,在深入研究这个问题并完全由它创建的时候,我看到了一些内容,即“查看活动监视器以查找”REAL“内存使用情况”。所以我只是发现“真实”内存正在攀升,直到大约250MB真实和480MB虚拟应用程序将崩溃。我正在释放我的记忆。当“实时”内存保持完美并且我可以钻进它时,如何确定消耗所有这些内存并使我的应用程序崩溃的内容,但是,活动监视器中的“REAL”内存失控并且没有办法钻进去了?
以下是我们用于处理图像的代码。这将拍摄图像,将其发送到第一个过滤器,分配过滤器,处理图像,释放分配的过滤器,然后将处理后的图像发送到下一个过滤器进行处理,具体取决于启用或不启用哪些过滤器。如果我在这里做错了什么我欢迎所有的批评和建议!我不是专业人士!就我而言,处理13个大小为1536 x 2048的图像不应该崩溃应用程序,如果你正确处理你的记忆。非常感谢你提前保存了我的头发。
吉姆
-(id)processFilters{
NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init];
self.previewView.image = [UIImage imageWithContentsOfFile:[self.documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"thumb_%@", self.file]]];
if (sephiaFilterEnabled){
sephiaFilter = [[GPUImageSepiaFilter alloc] init];
[(GPUImageSepiaFilter *)sephiaFilter setIntensity:[_filterSephiaSlider value]];
self.previewView.image = [sephiaFilter imageByFilteringImage:previewView.image];
[sephiaFilter release];
}
if (saturationFilterEnabled){
saturationFilter = [[GPUImageSaturationFilter alloc] init];
[(GPUImageSaturationFilter *)saturationFilter setSaturation:[_filterSaturationSlider value]];
self.previewView.image = [saturationFilter imageByFilteringImage:previewView.image];
[saturationFilter release];
}
if (contrastFilterEnabled){
contrastFilter = [[GPUImageContrastFilter alloc] init];
[(GPUImageContrastFilter *)contrastFilter setContrast:[_filterContrastSlider value]];
self.previewView.image = [contrastFilter imageByFilteringImage:previewView.image];
[contrastFilter release];
}
if (brightnessFilterEnabled){
brightnessFilter = [[GPUImageBrightnessFilter alloc] init];
[(GPUImageBrightnessFilter *)brightnessFilter setBrightness:[_filterBrightnessSlider value]];
self.previewView.image = [brightnessFilter imageByFilteringImage:previewView.image];
[brightnessFilter release];
}
if (exposureFilterEnabled){
exposureFilter = [[GPUImageExposureFilter alloc] init];
[(GPUImageExposureFilter *)exposureFilter setExposure:[_filterExposureSlider value]];
self.previewView.image = [exposureFilter imageByFilteringImage:previewView.image];
[exposureFilter release];
}
if (sharpenFilterEnabled){
sharpenFilter = [[GPUImageSharpenFilter alloc] init];
[(GPUImageSharpenFilter *)sharpenFilter setSharpness:[_filterSharpenSlider value]];
self.previewView.image = [sharpenFilter imageByFilteringImage:previewView.image];
[sharpenFilter release];
}
if (vignetteFilterEnabled){
vignetteFilter = [[GPUImageVignetteFilter alloc] init];
[(GPUImageVignetteFilter *)vignetteFilter setVignetteEnd:[_filterVignetteSlider value]];
self.previewView.image = [vignetteFilter imageByFilteringImage:previewView.image];
[vignetteFilter release];
}
if (gBlurFilterEnabled){
if(blurRadialEnabled){
gBlurFilter = [[GPUImageGaussianSelectiveBlurFilter alloc] init];
float yy;
float xx;
yy = blurToPoint.y / 320;
xx = blurToPoint.x / 240;
//NSLog (@"%f %f", xx, yy);
if(blurToPoint.x == 0 && blurToPoint.y == 0){
xx = 0.5;
yy = 0.5;
}
[(GPUImageGaussianSelectiveBlurFilter *)gBlurFilter setExcludeCirclePoint:CGPointMake(xx, yy)];
[(GPUImageGaussianSelectiveBlurFilter *)gBlurFilter setExcludeCircleRadius:[_filterGBlurSlider value]];
[(GPUImageGaussianSelectiveBlurFilter *)gBlurFilter setExcludeBlurSize:0.6];
self.previewView.image = [gBlurFilter imageByFilteringImage:previewView.image];
[gBlurFilter release];
}else if(blurBoxEnabled){
gBlurBoxFilter = [[GPUImageBoxBlurFilter alloc] init];
self.previewView.image = [gBlurBoxFilter imageByFilteringImage:previewView.image];
[gBlurBoxFilter release];
}else if(blurTiltEnabled){
gBlurTiltFilter = [[GPUImageTiltShiftFilter alloc] init];
float yy;
yy = blurToPoint.y / 320;
if(blurToPoint.y == 0){
yy = 0.5;
}
[(GPUImageTiltShiftFilter *)gBlurTiltFilter setTopFocusLevel:yy - [_filterTiltBlurSlider value]];
[(GPUImageTiltShiftFilter *)gBlurTiltFilter setBottomFocusLevel:yy + [_filterTiltBlurSlider value]];
self.previewView.image = [gBlurTiltFilter imageByFilteringImage:previewView.image];
[gBlurTiltFilter release];
}
}
if (cropFilterEnabled){
cropFilter = [[GPUImageCropFilter alloc] init];
float wBuff = [_filterCropSlider value] * cropToPoint.x;
float hBuff = [_filterCropSlider value] * cropToPoint.y;
float xp = cropToPoint.x - wBuff;
float yp = cropToPoint.y - hBuff;
float t1 = xp * [_filterCropSlider value];
float t2 = yp * [_filterCropSlider value];
xp = xp + (t1 * 4);
yp = yp + (t2 * 3.5);
xp = xp / 1000;
yp = yp / 1000;
//NSLog(@"%f, x: %f y: %f wB: %f hB: %f", [_filterCropSlider value], xp, yp, wBuff, hBuff);
[(GPUImageCropFilter *)cropFilter setCropRegion:CGRectMake(xp, yp, [_filterCropSlider value], [_filterCropSlider value])];
self.previewView.image = [cropFilter imageByFilteringImage:previewView.image];
[cropFilter release];
}
if (kuwaharaFilterEnabled){
kuwaharaFilter = [[GPUImageKuwaharaFilter alloc] init];
[(GPUImageKuwaharaFilter *)kuwaharaFilter setRadius:round([_filterKuwaharaSlider value])];
self.previewView.image = [kuwaharaFilter imageByFilteringImage:previewView.image];
[kuwaharaFilter release];
}
if (toonFilterEnabled){
toonFilter = [[GPUImageToonFilter alloc] init];
self.previewView.image = [toonFilter imageByFilteringImage:previewView.image];
[toonFilter release];
}
if (invertFilterEnabled){
invertFilter = [[GPUImageColorInvertFilter alloc] init];
self.previewView.image = [invertFilter imageByFilteringImage:previewView.image];
[invertFilter release];
}
if (pixelFilterEnabled){
pixelFilter = [[GPUImagePixellateFilter alloc] init];
[(GPUImagePixellateFilter *)pixelFilter setFractionalWidthOfAPixel:[_filterPixelSlider value]];
self.previewView.image = [pixelFilter imageByFilteringImage:previewView.image];
[pixelFilter release];
}
if (gammaFilterEnabled){
gammaFilter = [[GPUImageGammaFilter alloc] init];
[(GPUImageGammaFilter *)gammaFilter setGamma:[_filterGammaSlider value]];
self.previewView.image = [gammaFilter imageByFilteringImage:previewView.image];
[gammaFilter release];
}
if (sketchFilterEnabled){
sketchFilter = [[GPUImageSketchFilter alloc] init];
self.previewView.image = [sketchFilter imageByFilteringImage:previewView.image];
[sketchFilter release];
}
if (swirlFilterEnabled){
swirlFilter = [[GPUImageSwirlFilter alloc] init];
[(GPUImageSwirlFilter *)swirlFilter setAngle:[_filterSwirlSlider value]];
self.previewView.image = [swirlFilter imageByFilteringImage:previewView.image];
[swirlFilter release];
}
if (overlayFilterEnabled){
if (![self.overlayImage compare:@""] == NSOrderedSame){
GPUImageOutput<GPUImageInput> *overlayFilter;
if(multiplyBlendEnabled){
overlayFilter = [[GPUImageMultiplyBlendFilter alloc] init];
}else if(overlayBlendEnabled){
overlayFilter = [[GPUImageOverlayBlendFilter alloc] init];
}else if(lightenBlendEnabled){
overlayFilter = [[GPUImageLightenBlendFilter alloc] init];
}else if(darkenBlendEnabled){
overlayFilter = [[GPUImageDarkenBlendFilter alloc] init];
}else if(burnBlendEnabled){
overlayFilter = [[GPUImageColorBurnBlendFilter alloc] init];
}else if(dodgeBlendEnabled){
overlayFilter = [[GPUImageColorDodgeBlendFilter alloc] init];
}else if(screenBlendEnabled){
overlayFilter = [[GPUImageScreenBlendFilter alloc] init];
}else if(differenceBlendEnabled){
overlayFilter = [[GPUImageDifferenceBlendFilter alloc] init];
}else if(subtractBlendEnabled){
overlayFilter = [[GPUImageSubtractBlendFilter alloc] init];
}else if(exclusionBlendEnabled){
overlayFilter = [[GPUImageExclusionBlendFilter alloc] init];
}else if(hardLightBlendEnabled){
overlayFilter = [[GPUImageHardLightBlendFilter alloc] init];
}else if(softLightBlendEnabled){
overlayFilter = [[GPUImageSoftLightBlendFilter alloc] init];
}else{
overlayFilter = [[GPUImageMultiplyBlendFilter alloc] init];
}
UIImage *inputImage = [[[UIImage alloc]init]autorelease];
// The picture is only used for two-image blend filters
inputImage = [UIImage imageNamed:[NSString stringWithFormat:@"preview_%@.jpg", self.overlayImage]];
GPUImagePicture *sourcePreviewPicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];
[sourcePreviewPicture addTarget:overlayFilter];
inputImage = [overlayFilter imageByFilteringImage:self.previewView.image];
if(overlayOpacityFilterEnabled){
GPUImageOutput<GPUImageInput> *overlayOpacityFilter = [[GPUImageAlphaBlendFilter alloc] init];
sourcePreviewPicture = [[GPUImagePicture alloc] initWithImage:self.previewView.image smoothlyScaleOutput:YES];
[sourcePreviewPicture addTarget:overlayOpacityFilter];
[(GPUImageAlphaBlendFilter *)overlayOpacityFilter setMix:[_filterOverlayOpacitySlider value]];
inputImage = [overlayOpacityFilter imageByFilteringImage:inputImage];
[overlayOpacityFilter release];
}
self.previewView.image = inputImage;
[overlayFilter release];
[sourcePreviewPicture release];
}
}
if (borderFilterEnabled){
if (![self.borderImage compare:@""] == NSOrderedSame){
GPUImageOutput<GPUImageInput> *borderFilter;
if ([self.borderImage rangeOfString:@"black"].location == NSNotFound) {
borderFilter = [[GPUImageLightenBlendFilter alloc] init];
} else {
borderFilter = [[GPUImageMultiplyBlendFilter alloc] init];
}
UIImage *inputImage = [[[UIImage alloc]init]autorelease];
// The picture is only used for two-image blend filters
inputImage = [UIImage imageNamed:[NSString stringWithFormat:@"preview_%@.jpg", self.borderImage]];
GPUImagePicture *sourcePreviewPicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];
[sourcePreviewPicture addTarget:borderFilter];
self.previewView.image = [borderFilter imageByFilteringImage:self.previewView.image];
[borderFilter release];
[sourcePreviewPicture release];
}
}
[loopPool drain];
return self.previewView.image;
}