Skip to content

Commit 988f124

Browse files
mrunkelclaude
andcommitted
fix(jordanbaird#530): Remove expired CGImages from cache
Adapted from upstream PR jordanbaird#804 by Marc A. Runkel for the macos-26 baseline: the original referenced `MenuBarItemManager.ItemCache.allItems` (removed on macos-26 when ItemCache was simplified — the all/managed distinction was dropped). Replaced with `ItemCache.managedItems`. The cache-key type also changed: macos-26 keys MenuBarItemImageCache.images by `MenuBarItemTag`, not `MenuBarItemInfo`. Filter-then-merge order preserved from the original; behavioural intent is identical — sweep the image cache and drop entries whose key no longer matches any currently-managed menu bar item, addressing the memory growth reported in upstream issue jordanbaird#530. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 070cc03 commit 988f124

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Ice/MenuBar/MenuBarItems/MenuBarItemImageCache.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,13 @@ final class MenuBarItemImageCache: ObservableObject {
264264
newImages.merge(sectionImages) { (_, new) in new }
265265
}
266266

267-
await MainActor.run { [newImages] in
267+
// Adapted from upstream PR #804 by Marc A. Runkel (#530) — original used ItemCache.allItems; replaced with the macos-26 enumeration.
268+
let allValidTags = await Set(appState.itemManager.itemCache.managedItems.map(\.tag))
269+
270+
await MainActor.run { [newImages, allValidTags] in
271+
// Drop entries whose key no longer matches any currently-cached menu bar item.
272+
images = images.filter { allValidTags.contains($0.key) }
273+
// Merge in the freshly captured images.
268274
images.merge(newImages) { (_, new) in new }
269275
}
270276
}

0 commit comments

Comments
 (0)