When does a notification service extension process get terminated?

If there is the following code for a notification service extension

var countOfInvocations = 0

public class NotificationService: UNNotificationServiceExtension  {

    public override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        NSLog("Push count: \(countOfInvocations)")
        countOfInvocations = countOfInvocations + 1

Then if pushes are sent to the handset it can be observed in the console log that the value of countOfInvocations keeps increasing, meaning the NotificationService class is getting instantiated and destroyed within the same process. However at what point does that process get torn down by the OS? It seems to be kept alive for about 10 minutes or so. Is there a way the extension can detect its the same or a new process?

Smells like one of those many behaviors that is deliberately undocumented and could vary based on system conditions or across OS releases, so I’d be surprised if you get any specific official answer to this.

Is there a way the extension can detect its the same or a new process?

Your global countOfInvocations would restart at zero in a new process, right?

When does a notification service extension process get terminated?
 
 
Q