Ios 尝试使用核心图像模糊UIImage时内存泄漏
因此,在过去的几天里,我一直在挠头,试图修补内存泄漏,同时尝试使用核心图像模糊图像。我将内存泄漏追溯到这段代码:Ios 尝试使用核心图像模糊UIImage时内存泄漏,ios,objective-c,xcode,ciimage,Ios,Objective C,Xcode,Ciimage,因此,在过去的几天里,我一直在挠头,试图修补内存泄漏,同时尝试使用核心图像模糊图像。我将内存泄漏追溯到这段代码: - (void) blurImage { UIGraphicsBeginImageContext(self.view.bounds.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurr
- (void) blurImage {
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSLog(@"Captured Image");
@autoreleasepool {
CIImage *inputImage = [[CIImage alloc] initWithCGImage:image.CGImage];
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
[filter setValue:inputImage forKey:@"inputImage"];
[filter setValue:[NSNumber numberWithFloat:10.0] forKey:@"inputRadius"];
CIImage *result = [filter valueForKey:kCIOutputImageKey];
blur_image.image= [[UIImage alloc] initWithCIImage:result];
}
NSLog(@"blurred Image");
}
这段代码做两件事,它首先捕获当时屏幕的屏幕快照,然后模糊该图像并将其设置为int,以我的superview的背景中的图像视图
我使用选择器在后台运行来调用这段代码
- (void) viewDidAppear:(BOOL)animated{
SEL blur = @selector(blurImage);
[self performSelectorInBackground:blur withObject:nil];
}
我得到了一个与此代码相关的3个内存泄漏
这就是我提到的泄漏:
CoreImage CI::GLESContext::program_for_name(uu CFString const*)
我不知道我做错了什么,有人能告诉我吗?这里有几点
应该涵盖@autoreleasepool
方法中的所有代码blurImage
- ,所以你不必为此担心
performSelectorInBackground:withObject:
因容易泄漏而臭名昭著。此方法创建一个新线程并在该线程上运行选择器。您正在使用的某些UIKit功能在任何线程(主线程除外)上都不安全,这是不好的。然而,为了找到你的漏洞,发布一些工具的信息,比如使用漏洞工具的跟踪截图。哈哈,我没有足够的声誉,我会发布一个文本版本,虽然我已经决定使用苹果的uiimageview+effects标题,但我仍然想了解我在这里做错了什么。。。我不知道是什么导致内存泄漏。我尝试过CGImageReleasing(image.CGImage);图像分配。例如,图像
泄漏,因为它在没有自动释放池的情况下运行。但为什么会泄漏,我认为ARC管理所有Objective-C对象。ARC不管理对象,它只管理保留/释放/自动释放,它需要自动释放池才能正常工作。如果您看到main.m
文件,您将在那里看到@autoreleasepool
,因为它不是ARC提供的东西。