mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
Simplify iOS memory management, assuming swift(>=4.2)
This commit is contained in:
1 parent
b6f79f176c
commit
3eb36768c6
2 files changed
+22
-26
No files matched your search
@@ -177,13 +177,16 @@ extension DatabasePool {
|
||||
public func setupMemoryManagement(in application: UIApplication) {
|
||||
self.application = application
|
||||
let center = NotificationCenter.default
|
||||
#if swift(>=4.2)
|
||||
center.addObserver(self, selector: #selector(DatabasePool.applicationDidReceiveMemoryWarning(_:)), name: UIApplication.didReceiveMemoryWarningNotification, object: nil)
|
||||
center.addObserver(self, selector: #selector(DatabasePool.applicationDidEnterBackground(_:)), name: UIApplication.didReceiveMemoryWarningNotification, object: nil)
|
||||
#else
|
||||
center.addObserver(self, selector: #selector(DatabasePool.applicationDidReceiveMemoryWarning(_:)), name: .UIApplicationDidReceiveMemoryWarning, object: nil)
|
||||
center.addObserver(self, selector: #selector(DatabasePool.applicationDidEnterBackground(_:)), name: .UIApplicationDidEnterBackground, object: nil)
|
||||
#endif
|
||||
center.addObserver(
|
||||
self,
|
||||
selector: #selector(DatabasePool.applicationDidReceiveMemoryWarning(_:)),
|
||||
name: UIApplication.didReceiveMemoryWarningNotification,
|
||||
object: nil)
|
||||
center.addObserver(
|
||||
self,
|
||||
selector: #selector(DatabasePool.applicationDidEnterBackground(_:)),
|
||||
name: UIApplication.didReceiveMemoryWarningNotification,
|
||||
object: nil)
|
||||
}
|
||||
|
||||
@objc private func applicationDidEnterBackground(_ notification: NSNotification) {
|
||||
@@ -192,12 +195,7 @@ extension DatabasePool {
|
||||
}
|
||||
|
||||
let task: UIBackgroundTaskIdentifier = application.beginBackgroundTask(expirationHandler: nil)
|
||||
#if swift(>=4.2)
|
||||
let taskIsInvalid = task == UIBackgroundTaskIdentifier.invalid
|
||||
#else
|
||||
let taskIsInvalid = task == UIBackgroundTaskInvalid
|
||||
#endif
|
||||
if taskIsInvalid {
|
||||
if task == .invalid {
|
||||
// Perform releaseMemory() synchronously.
|
||||
releaseMemory()
|
||||
} else {
|
||||
|
||||
@@ -94,13 +94,16 @@ extension DatabaseQueue {
|
||||
public func setupMemoryManagement(in application: UIApplication) {
|
||||
self.application = application
|
||||
let center = NotificationCenter.default
|
||||
#if swift(>=4.2)
|
||||
center.addObserver(self, selector: #selector(DatabaseQueue.applicationDidReceiveMemoryWarning(_:)), name: UIApplication.didReceiveMemoryWarningNotification, object: nil)
|
||||
center.addObserver(self, selector: #selector(DatabaseQueue.applicationDidEnterBackground(_:)), name: UIApplication.didEnterBackgroundNotification, object: nil)
|
||||
#else
|
||||
center.addObserver(self, selector: #selector(DatabaseQueue.applicationDidReceiveMemoryWarning(_:)), name: .UIApplicationDidReceiveMemoryWarning, object: nil)
|
||||
center.addObserver(self, selector: #selector(DatabaseQueue.applicationDidEnterBackground(_:)), name: .UIApplicationDidEnterBackground, object: nil)
|
||||
#endif
|
||||
center.addObserver(
|
||||
self,
|
||||
selector: #selector(DatabaseQueue.applicationDidReceiveMemoryWarning(_:)),
|
||||
name: UIApplication.didReceiveMemoryWarningNotification,
|
||||
object: nil)
|
||||
center.addObserver(
|
||||
self,
|
||||
selector: #selector(DatabaseQueue.applicationDidEnterBackground(_:)),
|
||||
name: UIApplication.didEnterBackgroundNotification,
|
||||
object: nil)
|
||||
}
|
||||
|
||||
@objc private func applicationDidEnterBackground(_ notification: NSNotification) {
|
||||
@@ -109,12 +112,7 @@ extension DatabaseQueue {
|
||||
}
|
||||
|
||||
let task: UIBackgroundTaskIdentifier = application.beginBackgroundTask(expirationHandler: nil)
|
||||
#if swift(>=4.2)
|
||||
let taskIsInvalid = task == UIBackgroundTaskIdentifier.invalid
|
||||
#else
|
||||
let taskIsInvalid = task == UIBackgroundTaskInvalid
|
||||
#endif
|
||||
if taskIsInvalid {
|
||||
if task == .invalid {
|
||||
// Perform releaseMemory() synchronously.
|
||||
releaseMemory()
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user