Add method to post a low memory notification.

This commit is contained in:
Brent Simmons committed 2026-03-07 16:54:15 -08:00
1 parent c91fd29e44
commit 9143eee0c7
1 file changed
+15
@@ -6,9 +6,24 @@
//
import Foundation
import os
public extension Notification.Name {
/// Posted when the app should free memory — on background transition
/// and potentially on memory warnings. Always posted on the main thread.
static let lowMemory = Notification.Name("LowMemoryNotification")
}
private let lowMemoryLogger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "LowMemory")
public func postLowMemoryNotification() {
if Thread.isMainThread {
lowMemoryLogger.info("Posting low memory notification")
NotificationCenter.default.post(name: .lowMemory, object: nil)
} else {
Task { @MainActor in
lowMemoryLogger.info("Posting low memory notification")
NotificationCenter.default.post(name: .lowMemory, object: nil)
}
}
}