diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 4579742be..b5e081180 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -239,7 +239,6 @@ let appName = "NetNewsWire" ArticleThemesManager.shared.start() NetworkMonitor.shared.start() - MemoryPressureMonitor.shared.start() #if !SKIP_APP_GROUP_ACCESS ExtensionContainersFile.shared.start() diff --git a/Modules/Images/Sources/Images/IconImageDownloader.swift b/Modules/Images/Sources/Images/IconImageDownloader.swift index 0350fbe3a..9a8043311 100644 --- a/Modules/Images/Sources/Images/IconImageDownloader.swift +++ b/Modules/Images/Sources/Images/IconImageDownloader.swift @@ -45,7 +45,7 @@ public enum IconLookup { nonisolated static private let logger = Logger(subsystem: Logger.nnwSubsystem, category: "IconImageDownloader") - private let iconImages = NSCache() // url: icon image + private var iconImages = [String: IconImage]() // url: icon image private var urlsInProgress = Set() private var requestsToRetry = [String: Request]() // url: request that failed transiently @@ -64,7 +64,7 @@ public enum IconLookup { Self.logger.debug("Skipping non-http(s) URL: \(url)") return .unavailable } - if let iconImage = iconImages.object(forKey: url as NSString) { + if let iconImage = iconImages[url] { DownloadedImageCache.shared.imageWasUsed(url, checksForUpdates: true) return .found(iconImage) } @@ -87,11 +87,11 @@ public enum IconLookup { // MARK: - Notifications @objc func handleAppDidGoToBackground(_ notification: Notification) { - iconImages.removeAllObjects() + iconImages.removeAll() } @objc func handleLowMemory(_ notification: Notification) { - iconImages.removeAllObjects() + iconImages.removeAll() } /// Made again even when not in memory, since icons made from the old copy may be cached elsewhere. @@ -175,7 +175,7 @@ private extension IconImageDownloader { } func cacheIconImage(_ iconImage: IconImage, url: String) { - iconImages.setObject(iconImage, forKey: url as NSString) + iconImages[url] = iconImage NotificationCenter.default.post(name: .iconImageDidBecomeAvailable, object: self, userInfo: [Self.urlKey: url]) } diff --git a/Modules/RSCore/Sources/RSCore/MemoryPressureMonitor.swift b/Modules/RSCore/Sources/RSCore/MemoryPressureMonitor.swift deleted file mode 100644 index 7365671a8..000000000 --- a/Modules/RSCore/Sources/RSCore/MemoryPressureMonitor.swift +++ /dev/null @@ -1,32 +0,0 @@ -// -// MemoryPressureMonitor.swift -// RSCore -// -// Created by Brent Simmons on 3/7/26. -// - -#if os(macOS) - -import Foundation -import Dispatch - -/// Observes GCD memory pressure events on macOS. -/// Posts `.lowMemory` on warn or critical. -public final class MemoryPressureMonitor: Sendable { - public static let shared = MemoryPressureMonitor() - - private let source: DispatchSourceMemoryPressure - - init() { - source = DispatchSource.makeMemoryPressureSource(eventMask: [.warning, .critical], queue: .main) - source.setEventHandler { - AppNotification.postLowMemory() - } - } - - public func start() { - source.activate() - } -} - -#endif