mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 17:17:38 +00:00
The macOS helper serves each sidecar connection on a dedicated thread that lives as long as the connection, and the sidecar keeps one connection open while the helper runs. Encoding a screenshot with NSBitmapImageRep leaves autoreleased objects that keep the captured image alive, and that thread never drained its pool, so every screenshot kept a window-sized buffer in WindowServer until the helper restarted. Drain an autorelease pool around each request.
17 lines
664 B
Swift
17 lines
664 B
Swift
import Foundation
|
|
|
|
public enum AgentConnectionRequestLoop {
|
|
/// Serves request lines until `readLine` returns nil or `handle` returns false.
|
|
public static func run(readLine: () -> String?, handle: (String) -> Bool) {
|
|
var keepServing = true
|
|
while keepServing {
|
|
// Why: a connection thread outlives its requests; without a per-request pool, objects
|
|
// autoreleased while encoding a screenshot keep its WindowServer buffer until disconnect.
|
|
keepServing = autoreleasepool {
|
|
guard let line = readLine() else { return false }
|
|
return handle(line)
|
|
}
|
|
}
|
|
}
|
|
}
|