KVO observation info is lost causing a crash when removing observers

Hi everyone.

When iOS 14 beta 5 was released we started getting a crash on our app, the classic "Cannot remove an observer <XYZBinding 0x600000d6b750> for the key path "state" from <XYZEntryChat 0x7f960a77a900> because it is not registered as an observer.".

However, nothing had changed in our code base to justify that, indeed the code that was crashing hadn't been changed in several months. The crash persists even in the official iOS 14 release.

We investigated and, by chance, found that the observationInfo object in XYZEntryChat, that should hold the information about the registered observers, is being deallocated after being created, without any intervention from our part.

Also by chance, we found that overriding either the - (void)setObservationInfo:(void *)observationInfo method or the observationInfo getter in the XYZEntryChat class the issue no longer occurs.

In many other classes that use the same base code to handle bindings the issue does not occur.

We have no further leads on why this is happening, it may be an iOS 14 bug or some behaviour change on iOS 14 that uncovered a wrong usage flow in our app. We also investigated if it was related to Objective-C / Swift interoperability, but other classes that also use / are used by Swift don't have the issue.

Has anyone ever came across this behaviour or has any idea of what the root cause may be?

Thanks in advance.

Replies

iOS 14 and friends include a KVO change that allows it to reliable flag usage issues that previously resulted in very-hard-to-debug problems. See the Key-Value Observing section of the iOS & iPadOS 14 Release Notes for details. It’s possible that your code is doing something that’s causing this mechanism to fail but, honestly, it seems more likely that this mechanism is correctly detecting a latent bug in your KVO handling.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"