I use Realm for Swift with memory only configuration. Because of updating the database in background thread I create a Realm instance every time I use it. This was mentioned in the Realm documentation and another question here https://stackoverflow.com/a/45375608/613121.
But by testing the database I notice an unpredictable behaviour. Sometimes the database was empty and the update refills the database instead of an update. The reason seams to be that the Realm was deallocated after the writing.
The solution may be to hold a strong reference in the main thread. I save the Realm configuration in a singleton. Would it be safe that the singleton returns a new Realm with same configuration for updates and hold a strong reference to another Realm for preventing losses?