From 9143eee0c7e4990e4f66063bd583e1f656ec2003 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 7 Mar 2026 16:54:15 -0800 Subject: [PATCH] Add method to post a low memory notification. --- Modules/RSCore/Sources/RSCore/Notifications.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Modules/RSCore/Sources/RSCore/Notifications.swift b/Modules/RSCore/Sources/RSCore/Notifications.swift index 284be7b69..80aebf504 100644 --- a/Modules/RSCore/Sources/RSCore/Notifications.swift +++ b/Modules/RSCore/Sources/RSCore/Notifications.swift @@ -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) + } + } +}