Nil check needed here (#32689)

* Nil check needed here

* Restyled by clang-format

* Adding pools here

* Restyled by whitespace

* Restyled by clang-format

* Upping this queue

* Removing autorelease calls

* Restyled by whitespace

* Removing these too

---------

Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm
index 9e2d169..c58c766 100644
--- a/src/darwin/Framework/CHIP/MTRDevice.mm
+++ b/src/darwin/Framework/CHIP/MTRDevice.mm
@@ -1035,9 +1035,11 @@
     MTRWeakReference<MTRDevice *> * weakSelf = [MTRWeakReference weakReferenceWithObject:self];
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (kTimeToWaitBeforeMarkingUnreachableAfterSettingUpSubscription * NSEC_PER_SEC)), self.queue, ^{
         MTRDevice * strongSelf = weakSelf.strongObject;
-        os_unfair_lock_lock(&strongSelf->_lock);
-        [strongSelf _markDeviceAsUnreachableIfNotSusbcribed];
-        os_unfair_lock_unlock(&strongSelf->_lock);
+        if (strongSelf != nil) {
+            os_unfair_lock_lock(&strongSelf->_lock);
+            [strongSelf _markDeviceAsUnreachableIfNotSusbcribed];
+            os_unfair_lock_unlock(&strongSelf->_lock);
+        }
     });
 
     [_deviceController
diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm
index 6ed3b00..2b7c8d5 100644
--- a/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm
+++ b/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm
@@ -125,6 +125,12 @@
 
     __block id resumptionNodeList;
     dispatch_sync(_storageDelegateQueue, ^{
+        @autoreleasepool {
+            resumptionNodeList = [_storageDelegate controller:_controller
+                                                  valueForKey:sResumptionNodeListKey
+                                                securityLevel:MTRStorageSecurityLevelSecure
+                                                  sharingType:MTRStorageSharingTypeNotShared];
+        }
         resumptionNodeList = [_storageDelegate controller:_controller
                                               valueForKey:sResumptionNodeListKey
                                             securityLevel:MTRStorageSecurityLevelSecure
@@ -145,6 +151,7 @@
     } else {
         _nodesWithResumptionInfo = [[NSMutableArray alloc] init];
     }
+
     return self;
 }
 
@@ -233,10 +240,12 @@
 {
     __block id data;
     dispatch_sync(_storageDelegateQueue, ^{
-        data = [_storageDelegate controller:_controller
-                                valueForKey:sLastLocallyUsedNOCKey
-                              securityLevel:MTRStorageSecurityLevelSecure
-                                sharingType:MTRStorageSharingTypeNotShared];
+        @autoreleasepool {
+            data = [_storageDelegate controller:_controller
+                                    valueForKey:sLastLocallyUsedNOCKey
+                                  securityLevel:MTRStorageSecurityLevelSecure
+                                    sharingType:MTRStorageSharingTypeNotShared];
+        }
     });
 
     if (data == nil) {
@@ -259,10 +268,12 @@
 
     __block id resumptionInfo;
     dispatch_sync(_storageDelegateQueue, ^{
-        resumptionInfo = [_storageDelegate controller:_controller
-                                          valueForKey:key
-                                        securityLevel:MTRStorageSecurityLevelSecure
-                                          sharingType:MTRStorageSharingTypeNotShared];
+        @autoreleasepool {
+            resumptionInfo = [_storageDelegate controller:_controller
+                                              valueForKey:key
+                                            securityLevel:MTRStorageSecurityLevelSecure
+                                              sharingType:MTRStorageSharingTypeNotShared];
+        }
     });
 
     if (resumptionInfo == nil) {
@@ -304,11 +315,12 @@
 - (id)_fetchAttributeCacheValueForKey:(NSString *)key expectedClass:(Class)expectedClass;
 {
     id data;
-    data = [_storageDelegate controller:_controller
-                            valueForKey:key
-                          securityLevel:MTRStorageSecurityLevelSecure
-                            sharingType:MTRStorageSharingTypeNotShared];
-
+    @autoreleasepool {
+        data = [_storageDelegate controller:_controller
+                                valueForKey:key
+                              securityLevel:MTRStorageSecurityLevelSecure
+                                sharingType:MTRStorageSharingTypeNotShared];
+    }
     if (data == nil) {
         return nil;
     }
diff --git a/src/platform/Darwin/PlatformManagerImpl.cpp b/src/platform/Darwin/PlatformManagerImpl.cpp
index 5db5c69..0edc652 100644
--- a/src/platform/Darwin/PlatformManagerImpl.cpp
+++ b/src/platform/Darwin/PlatformManagerImpl.cpp
@@ -169,7 +169,10 @@
 {
     if (mWorkQueue == nullptr)
     {
-        mWorkQueue = dispatch_queue_create(CHIP_CONTROLLER_QUEUE, DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL);
+        mWorkQueue =
+            dispatch_queue_create(CHIP_CONTROLLER_QUEUE,
+                                  dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL,
+                                                                          QOS_CLASS_USER_INITIATED, QOS_MIN_RELATIVE_PRIORITY));
         dispatch_suspend(mWorkQueue);
         dispatch_queue_set_specific(mWorkQueue, &sPlatformManagerKey, this, nullptr);
         mIsWorkQueueSuspended = true;