Number of active versions increases continuously using SwiftUI ForEach and ObservedResults

Hi there,

I’ve recently migrated some code in one of my projects from using a ‘self-built’ ObservedResults solution with a UITableView to the one provided by Realm Swift with a SwiftUI native view using LazyVStack and ForEach - thanks for implementing that by the way.

The issue I’m facing now is that as my app runs and continues to modify/append items to the database (in collections OTHER to the ones being displayed) for some reason the number of active versions continues to grow and eventually crashes the application.
Either with a message indicating the maximum number of application versions being exceeded or if I remove that limit with another more nefarious looking crash reason significantly later on.

I believe I’ve isolated this to the use of LazyVStack/List/ForEach as if I remove this code or iterate over the Results indices instead of the Results directly the application does not eventually crash.

Any ideas for fixing this pinning issue?
I’d rather get this working than revert to the UITableView + ObservationToken implementation.


Actually - this appears to happen more generally with the use of ObservedRealmObject as well… :confused:

It’s difficult to say considering your solution is ‘self-built’, but– given the existing implementation of ObservedResults and ObservedRealmObject, there is no way around the pinning issue. Unfortunately, by having to use frozen objects to allow for SwiftUIs data binding to function properly, version pinning is unavoidable.

We do hope to fix this in the future though.