I'm having an issue with CoreImage's CIImage when using it to load multiple images in a Swift 4 project on macOS Mojave using Xcode 10-latest.
I'm using code similar to this:
@IBAction func loadImages(sender: Any?) {
let panel = NSOpenPanel()
panel.allowsMultipleSelection = true
panel.allowedFileTypes = [kUTTypeImage as String]
let result = panel.runModal()
if (result.rawValue == NSFileHandlingPanelOKButton) {
for url in panel.urls {
let image = CIImage(contentsOf: url)
print(image!.extent.width)
}
}
}
If I use this code & load a good amount of larger, high-quality images, my app will consume hundreds of MBs of RAM even long after that function has run for no apparent reason. It seems that the CIImage objects are just not being released even after they are no longer being used inside this function.
Having found two answers to similar problems (answer 1 & answer 2) I would've assumed that wrapping the code dealing with CIImages inside an autoreleasepool{}
clojure would solve my problem, but the issue still persists when my code looks like so:
@IBAction func loadImages(sender: Any?) {
autoreleasepool {
let panel = NSOpenPanel()
panel.allowsMultipleSelection = true
panel.allowedFileTypes = [kUTTypeImage as String]
let result = panel.runModal()
if (result.rawValue == NSFileHandlingPanelOKButton) {
for url in panel.urls {
let image = CIImage(contentsOf: url)
print(image!.extent.width)
}
}
}
}
Am I just missing some sort of fundamental knowledge of Swift memory management basics here or is this actually a bug that I have to somehow work around?
Any help would be greatly appreciated.