How to determine when iOS app notification service extension process is about to be terminated?

class NotificationService: UNNotificationServiceExtension {
    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        // call content handler here when ready
    }

    override func serviceExtensionTimeWillExpire() {
        // call content handler here with the best attempt
    }
}

As I understand, for each notification a new instance of NotificationService is created, but all these instances can be in the same process that may share access to the database, network connections and other resources - iOS doesn't start a new NSE process for each new notification, and connecting/disconnecting to/from these resources for each notification would be very inefficient.

At some point iOS kills NSE process, and in some cases it results in the exception with 0xdead10cc exit code ("dead lock") that is visible to the users as an alert about the crash of the app in the background.

Is there a way to determine when iOS is about to kill NSE process to release the resources?

How to determine when iOS app notification service extension process is about to be terminated?
 
 
Q