     }
 
     private func updateDatabaseModelsSystemFieldsAfterUpload(with records: [CKRecord]) {
-        performRealmOperations { realm in
+        performRealmOperations { [weak self] realm in
+            guard let self = self else { return }
+
             records.forEach { record in
-                guard let modelType = realmModel(for: record.recordType) else {
+                guard let modelType = self.realmModel(for: record.recordType) else {
                     os_log("There's no corresponding Realm model type for record type %{public}@",
-                           log: log,
+                           log: self.log,
                            type: .error,
                            record.recordType)
                     return


                guard var object = realm.object(ofType: modelType, forPrimaryKey: record.recordID.recordName) as? HasCloudKitFields else {
                    os_log("Unable to find record type %{public}@ with primary key %{public}@ for update after sync upload",
                           log: log,
                           type: .error,
                           record.recordType,
                           record.recordID.recordName)


                object.ckFields = record.encodedSystemFields

                os_log("Updated ckFields in record of type %{public}@", log: self.log, type: .debug, record.recordType)
            }
        }
    }
