Best practice to use Realm Swift in Background Worker Thread?

The sample (crashing on long-term usage) source code of the whole app is available here:

Problem: Realm file grows up to 7Gb and finally crashes the app on launch.

I’ve created GitHub issue, but want to ask here as well. Any hints to fix the crashes, except for my current strategy:

you may call invalidate on Realm
use shouldCompactOnLaunch
wrap Realm usage into autoreleasepool


First thing I’ve done - added Realm invalidation on daemon stop:

Second thing - compact Realm: