From 99c243a51cc7b7e4ddb1275565a3813ef8dc83af Mon Sep 17 00:00:00 2001 From: maxsoch Date: Mon, 6 Jul 2026 21:33:32 +0200 Subject: [PATCH] fix: cap logBuffer at 100k chars to prevent unbounded growth Every brew command appended its full output to logBuffer and nothing ever trimmed it, so with the hourly refresh timer the buffer grew forever. Memory aside, each log() call re-renders the entire buffer into the log window's NSTextView, so logging got slower over time. Keep only the most recent 100k characters, dropping the oldest content. Co-Authored-By: Claude Fable 5 --- BrewBar/BrewBarApp.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/BrewBar/BrewBarApp.swift b/BrewBar/BrewBarApp.swift index be2a4fd..9db5507 100644 --- a/BrewBar/BrewBarApp.swift +++ b/BrewBar/BrewBarApp.swift @@ -344,9 +344,16 @@ class AppDelegate: NSObject, NSApplicationDelegate { // MARK: - Logs + /// oldest content is dropped past this size, or the buffer grows forever + /// and every log() re-renders an ever-larger string into the text view + let maxLogLength = 100_000 + func log(_ text: String) { DispatchQueue.main.async { self.logBuffer += text + if self.logBuffer.count > self.maxLogLength { + self.logBuffer = String(self.logBuffer.suffix(self.maxLogLength)) + } self.logWindow?.update(text: self.logBuffer) } }