gpt4 book ai didi

objective-c - CIContext内存泄漏

转载 作者:行者123 更新时间:2023-12-03 16:35:17 24 4
gpt4 key购买 nike

+ (CGImageRef) newFliteredCGImage:(CGImageRef)image withCIFilter:(CIFilter*)filter {
CIImage* input_image = [CIImage imageWithCGImage:image];
NSSize image_size = NSMakeSize(CGImageGetWidth(image),
CGImageGetHeight(image));

[filter setValue:input_image forKey:kCIInputImageKey];
CIImage* output_image = [filter valueForKey:kCIOutputImageKey];

CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
CGContextRef bitmap_context
= CGBitmapContextCreate(nil,
image_size.width,
image_size.height,
8,
image_size.width * 4,
color_space,
(CGBitmapInfo)kCGImageAlphaNoneSkipFirst);
CGColorSpaceRelease(color_space);

CIContext* ci_bitmap_context
= [CIContext contextWithCGContext:bitmap_context
options:nil];
[ci_bitmap_context drawImage:output_image
inRect:[output_image extent]
fromRect:(CGRect){CGPointZero, image_size}];

CGImageRef result_img = CGBitmapContextCreateImage(bitmap_context);

CGContextRelease(bitmap_context);

return result_img;
}

参数的CGImageRef和返回的CGImageRef被CGImageRelease释放,但存在内存泄漏

我认为 CIContext 有问题,但我找不到问题

请给我帮助

最佳答案

在@autoReleasePool中执行它..

+ (CGImageRef) newFliteredCGImage:(CGImageRef)image withCIFilter:(CIFilter*)filter {

@autoreleasepool {
CIImage* input_image = [CIImage imageWithCGImage:image];
NSSize image_size = NSMakeSize(CGImageGetWidth(image),
CGImageGetHeight(image));

[filter setValue:input_image forKey:kCIInputImageKey];
CIImage* output_image = [filter valueForKey:kCIOutputImageKey];

CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
CGContextRef bitmap_context
= CGBitmapContextCreate(nil,
image_size.width,
image_size.height,
8,
image_size.width * 4,
color_space,
(CGBitmapInfo)kCGImageAlphaNoneSkipFirst);

CIContext* ci_bitmap_context
= [CIContext contextWithCGContext:bitmap_context
options:nil];
[ci_bitmap_context drawImage:output_image
inRect:[output_image extent]
fromRect:(CGRect){CGPointZero, image_size}];

CGImageRef result_img = CGBitmapContextCreateImage(bitmap_context);

return result_img;

}
}

希望对你有帮助..

关于objective-c - CIContext内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33249700/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com