Handle low memory notification.

This commit is contained in:
Brent Simmons committed 2026-03-07 17:13:37 -08:00
1 parent b080735211
commit a760d30cd3
1 file changed
+14 -5
+14 -5
View File
@@ -9,6 +9,7 @@
import Foundation
import Account
import Articles
import RSCore
@MainActor final class IconImageCache {
@@ -20,6 +21,14 @@ import Articles
private var smallIconImageCache = [SidebarItemIdentifier: IconImage]()
private var authorIconImageCache = [Author: IconImage]()
init() {
NotificationCenter.default.addObserver(self, selector: #selector(handleLowMemory(_:)), name: .lowMemory, object: nil)
}
@objc func handleLowMemory(_ notification: Notification) {
emptyCache()
}
func imageFor(_ feedID: SidebarItemIdentifier) -> IconImage? {
if let smartFeed = SmartFeedsController.shared.find(by: feedID) {
return imageForFeed(smartFeed)
@@ -59,11 +68,11 @@ import Articles
}
func emptyCache() {
smartFeedIconImageCache = [SidebarItemIdentifier: IconImage]()
feedIconImageCache = [SidebarItemIdentifier: IconImage]()
faviconImageCache = [SidebarItemIdentifier: IconImage]()
smallIconImageCache = [SidebarItemIdentifier: IconImage]()
authorIconImageCache = [Author: IconImage]()
smartFeedIconImageCache.removeAll()
feedIconImageCache.removeAll()
faviconImageCache.removeAll()
smallIconImageCache.removeAll()
authorIconImageCache.removeAll()
}
}