问题描述
还有其他人遇到过这个问题吗?由于CGBitmapContextCreateImage,ObjectAlloc爬升。 Apple的软件没有完全释放objectalloc吗?
Has anyone else come across this problem? ObjectAlloc climbs as a result of the CGBitmapContextCreateImage. Does Apple's software not fully releasing the objectalloc?
我使用NSTimer每秒调整12次图像大小。在调整图像大小的过程中,我还通过包含interpolationQuality来添加类似高斯模糊效果的Photoshop。
I am resizing images 12 times a second with a NSTimer. During resizing of the image I am also adding a photoshop like Gaussian blur effect by including interpolationQuality.
使用仪器后,它没有显示任何内存泄漏但我的objectalloc只是继续爬升。它直接指向 CGBitmapContextCreateImage 。
CGBitmapContextCreateImage> create_bitmap_ data_provide> malloc
After using Instruments it does not show any memory leaks but my objectalloc just continues to climb. It points directly to CGBitmapContextCreateImage.
CGBitmapContextCreateImage > create_ bitmap_ data_provide > malloc
任何人知道解决方案吗?或者甚至是可能的想法?
Anyone know of a solution? or Even possible ideas?
NSTimer中的电话
NSString * fileLocation = [[NSBundle mainBundle] pathForResource:imgMain ofType:@"jpg"];
NSData * imageData = [NSData dataWithContentsOfFile:fileLocation];
UIImage * blurMe = [UIImage imageWithData:imageData];
CGRect rect = CGRectMake(0, 0, round(blurMe.size.width /dblBlurLevel), round(blurMe.size.width /dblBlurLevel));
UIImage * imageShrink = [self resizedImage: blurMe : rect : 3.0];
CGRect rect2 = CGRectMake(0, 0, blurMe.size.width , blurMe.size.width );
UIImage * imageReize = [self resizedImage: imageShrink : rect2 : 3.0];
imgView.image = imageReize;
调整大小功能
-(UIImage *) resizedImage:(UIImage *)inImage : (CGRect)thumbRect : (double)interpolationQuality
{
CGImageRef imageRef = [inImage CGImage];
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);
if (alphaInfo == kCGImageAlphaNone)
alphaInfo = kCGImageAlphaNoneSkipLast;
// Build a bitmap context that's the size of the thumbRect
CGContextRef bitmap = CGBitmapContextCreate(
NULL,
thumbRect.size.width,
thumbRect.size.height,
CGImageGetBitsPerComponent(imageRef),
4 * thumbRect.size.width,
CGImageGetColorSpace(imageRef),
alphaInfo
);
// Draw into the context, this scales the image
CGContextSetInterpolationQuality(bitmap, interpolationQuality);
CGContextDrawImage(bitmap, thumbRect, imageRef);
// Get an image from the context and a UIImage
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage* result = [UIImage imageWithCGImage:ref];
CGContextRelease(bitmap); // ok if NULL
CGImageRelease(ref);
return [result autorelease];
}
推荐答案
该代码过度发布结果
。
也就是说,问题可能是UIImage没有被释放,而UIImage正在抓住CGImage,CGImage正在抓住内存在CGBitmapContextCreate下分配。
That said, it's likely that the issue is that the UIImage is not getting deallocated, and the UIImage is holding onto the CGImage, and the CGImage is holding onto the memory that was allocated under CGBitmapContextCreate.
使用工具查看UIImages是否未被解除分配,如果是,请尝试调试原因。
Use instruments to see if UIImages are not getting deallocated, and if so try to debug why.
这篇关于iPhone - 多个CGBitmapContextCreateImage调用 - ObjectAlloc攀爬的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!