Skip to content

Commit e86993f

Browse files
committed
fix(#530): Remove expired CGImages from cache
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.
1 parent 11edd39 commit e86993f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Ice/MenuBar/MenuBarItems/MenuBarItemImageCache.swift

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

215-
await MainActor.run { [newImages] in
215+
// Get the set of valid item infos from all sections to clean up stale entries
216+
let allValidInfos = await Set(appState.itemManager.itemCache.allItems.map(\.info))
217+
218+
await MainActor.run { [newImages, allValidInfos] in
219+
// Remove images for items that no longer exist in the item cache
220+
images = images.filter { allValidInfos.contains($0.key) }
221+
// Merge in the new images
216222
images.merge(newImages) { (_, new) in new }
217223
}
218224

0 commit comments

Comments
 (0)