环境:
我对NSImage具有以下扩展名:
extension NSImage {
func filter(filter: String) -> NSImage? {
return autoreleasepool { [weak self] () -> NSImage? in
let image = CIImage(data: (self?.tiffRepresentation!)!)
if let filter = CIFilter(name: filter) {
filter.setDefaults()
filter.setValue(image, forKey: kCIInputImageKey)
let context = CIContext(options: [CIContextOption.useSoftwareRenderer: true])
// *** 64 Byte MEMORY LEAK on line below ***
guard let imageRef = context.createCGImage(filter.outputImage!, from: image!.extent) else {
context.clearCaches()
context.reclaimResources()
return nil
}
context.clearCaches()
context.reclaimResources()
return NSImage(cgImage: imageRef, size: NSSize(width: 0, height: 0))
} else {
return nil
}
}
}
}
要反转的图像是在InterfaceBuilder中设置的,并且是16KB 480x480 png,带有alpha通道和sRGB IEC61966-2.1颜色配置文件。我从子类化的NSButton 中调用“ filter”函数,如下所示:
...
override func awakeFromNib() {
....
autoreleasepool {
image = image!.filter(filter: "CIColorInvert")
}
....
}
...
该过滤器按公布的方式工作。但是,在受保护的“ context.createCGImage ”调用中,出现了64字节内存泄漏。
我尝试过的事情:
相同的结果:在上面指示的行有64字节的Malloc内存泄漏。我想念什么?