Skip to content

fix: evict stale CGImages from menu bar item cache#1

Merged
restocked merged 1 commit into
mainfrom
fix/cache-evict-expired-images
Apr 29, 2026
Merged

fix: evict stale CGImages from menu bar item cache#1
restocked merged 1 commit into
mainfrom
fix/cache-evict-expired-images

Conversation

@restocked

Copy link
Copy Markdown
Owner

Cherry-picked from upstream PR jordanbaird/Ice#804 by @mrunkel (commit attribution preserved).

Summary

  • Before merging newly-captured images into MenuBarItemImageCache.images, filter the cache down to keys still present in MenuBarItemManager.itemCache.allItems.
  • Prevents unbounded growth caused by orphaned (bundleID, title) keys when menu bar items change titles or apps quit.

Why

The cache previously only ever called images.merge(...) and never removed keys. Items with dynamic titles (Stats, Itsycal, Spotify, etc.) produce a new MenuBarItemInfo every time the title changes; old keys stay in memory forever, each holding a backing-scale CGImage. Upstream issue #530 reports up to ~4 GB after long uptime; the PR author saw 983 MB after 15 days. Locally we see ~300 MB after several days.

This is the minimum floor for the leak — a follow-up will likely also prune when no UI is visible (current updateCache() early-returns when Ice Bar / Search / Settings are hidden, so eviction doesn't run in steady state).

Test plan

  • Build runs (verified locally; only signing-cert configuration blocks xcodebuild for now).
  • Manually exercise: open Ice Bar / Settings → Menu Bar Layout to trigger cache refresh. Confirm MenuBarItemImageCache.images.count no longer grows beyond the live item count.
  • Long-running soak: leave running 24h+ with apps that update titles (e.g. Stats, Itsycal). Confirm RSS stays bounded.

On long running systems, the cache would continue to grow.

On my system, after running for 15 days, the Cache 983MB, almost of the total memory usage.
@restocked restocked merged commit c7862fb into main Apr 29, 2026
@restocked restocked deleted the fix/cache-evict-expired-images branch April 29, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants