有没有其他人遇到过这个问题?ObjectAlloc 作为 CGBitmapContextCreateImage 的结果而攀升。苹果的软件没有完全释放objectalloc吗?
我正在使用 NSTimer 每秒 12 次调整图像大小。在调整图像大小的过程中,我还通过包含插值质量来添加像高斯模糊效果这样的 Photoshop。
使用 Instruments 后,它没有显示任何内存泄漏,但我的 objectalloc 继续攀升。它直接指向CGBitmapContextCreateImage。
CGBitmapContextCreateImage > create_bitmap_data_provide > malloc
有人知道解决方案吗?甚至可能的想法?
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];
}