     }
 
     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)


        os_log("Will commit %{public}d changed record(s) to the database", log: log, type: .info, records.count)

        performRealmOperations { [weak self] queueRealm in
            guard let self = self else { return }

            records.forEach { record in
                switch record.recordType {
                case RecordTypes.favorite:
                    self.commit(objectType: Favorite.self, with: record, in: queueRealm)
                case RecordTypes.bookmark:
                    self.commit(objectType: Bookmark.self, with: record, in: queueRealm)
                case RecordTypes.sessionProgress:
                    self.commit(objectType: SessionProgress.self, with: record, in: queueRealm)
                default:
                    os_log("Unknown record type %{public}@", log: self.log, type: .fault, record.recordType)
                }
