Empty more caches — reclaim more memory — on app resigning active.

This commit is contained in:
Brent Simmons 2024-06-08 12:12:43 -07:00
parent 4ec5990d8b
commit 447aa7a448
3 changed files with 24 additions and 2 deletions

View File

@ -327,8 +327,17 @@ import Sparkle
}
func applicationDidResignActive(_ notification: Notification) {
ArticleStringFormatter.emptyCaches()
MultilineTextFieldSizer.emptyCache()
IconImageCache.shared.emptyCache()
accountManager.emptyCaches()
saveState()
Task.detached {
await DownloadWithCacheManager.shared.cleanupCache()
}
}
func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String : Any]) {

View File

@ -142,8 +142,7 @@ public final actor DownloadWithCacheManager {
public func download(_ url: URL, forceRedownload: Bool = false) async throws -> DownloadData {
if lastCleanupDate.timeIntervalSinceNow < -DownloadWithCacheManager.cleanupInterval {
lastCleanupDate = Date()
cache.cleanup(DownloadWithCacheManager.timeToLive)
cleanupCache()
}
if !forceRedownload {
@ -161,4 +160,9 @@ public final actor DownloadWithCacheManager {
return downloadData
}
public func cleanupCache() {
lastCleanupDate = Date()
cache.cleanup(DownloadWithCacheManager.timeToLive)
}
}

View File

@ -143,7 +143,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}
func applicationDidEnterBackground(_ application: UIApplication) {
ArticleStringFormatter.emptyCaches()
MultilineUILabelSizer.emptyCache()
SingleLineUILabelSizer.emptyCache()
IconImageCache.shared.emptyCache()
accountManager.emptyCaches()
Task.detached {
await DownloadWithCacheManager.shared.cleanupCache()
}
}
// MARK: Notifications