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 activity monitor, 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 don't use 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?
Ok, I found this answer: Why is NSOpenPanel/NSSavePanel showing memory leak?
It says that NSOpenPanel/NSSavePanel are singletons where "the first time you call [them], an instance of NSOpenPanel is created and not released. This is not a leak, it's an optimisation."
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.