当前代码:
#!/usr/bin/swift
import Foundation
func runSleepProcess() {
let sleepProcess = Process()
sleepProcess.executableURL = URL(fileURLWithPath: "/bin/sleep")
sleepProcess.arguments = ["0"]
try? sleepProcess.run()
sleepProcess.waitUntilExit()
}
while true {
runSleepProcess()
}
在活动监视器中查看,似乎每次循环时mach端口使用量会增加1。当运行外部进程时,这是预期的行为吗?如果不是,我该如何修复泄漏?谢谢。