I have a SwiftUI/AppKit app (for compatibility with macos 10.15).
I have successfully implemented an open and a save file method using NSOpenPanel and NSSavePanel.
I noticed in macOS' activity monitor, that the 2 processes com.apple.appkit.xpc.openAndSavePanelService ...and QuickLookUIService (com.apple.appkit.xpc.openAndSavePanelService ... open as soon as my methods are called, but they never terminate. After open/save is finished, they use only minimal CPU and little memory (19 & 3 MB).
I don't see problems so far, but I wonder why those helper processes don't terminate/deallocate.
Here's my code in my AppDelegate:
@IBAction func openDocument(_ sender: Any?) {
let openPanel = NSOpenPanel()
openPanel.prompt = "Import"
openPanel.title = "Choose a .plist file"
openPanel.titleVisibility = .visible
openPanel.canCreateDirectories = false
openPanel.allowedFileTypes = ["plist"] // TODO: deprecated in macOS 12
openPanel.setFrameAutosaveName("Open Panel")
let result = openPanel.runModal()
if result == .OK {
if let fileUrl = openPanel.url {
let path = fileUrl.path
print("selected file to open: '\(path)'")
loadArray(from: fileUrl)
}
} else if result == .cancel {
print("Open document (Import Actions) was cancelled")
}
}
Is this behaviour of the XPC processes normal, or a bug/leak?
Ok, I found this answer: Why is NSOpenPanel/NSSavePanel showing memory leak?
It says that
NSOpenPanel/NSSavePanelare singletons where "the first time you call [them], an instance ofNSOpenPanelis created and not released. This is not a leak, it's an optimisation."