1

Right now synchronous RealmQueries (with multiple sort fields on 35k objects) are slowing down my main thread, even after their Activity was closed.

Currently I cannot use asynchronous queries due to a BadVersionException, I have not yet figured out why.

Anyway, there is no way to stop these RealmResults from auto-updating and blocking the main thread without closing the associated Realm, right?

I hoped I would be able to use just one global Realm instance, but this seems to leave me unable to stop mentioned RealmResults until I hit the GC button in the Android Monitor to force garbage collection on the RealmResults.

I did want to use just one Realm instance since it was recommended by an iOS colleague to hopefully fix the BadVersionException (for more on the BadVersionException I already have another question open).

Should I continue to focus on fixing the issue that prevents me from using asynchronous queries, or is there something that I did not consider that could help me to at least temporarly migitate slow synchronous queries that keep blocking the main thread?

It is not hard to explain that queries on the data are slowing down the UI and we are working on moving them into the background, however, it is hard to explain that queries on a screen that is not open are still slowing down the main thread.

Community
  • 1
  • 1
ferbeb
  • 163
  • 1
  • 2
  • 11
  • 1
    https://github.com/realm/realm-java/pull/3834 will probably fix your issue. after that merged all queries will be running asynchronously as much as possible. Currently, if you want to stop updating a synchronized query, you can 1) set the `RealmResults` to null it will be no longer updated after it gets GCed; or 2) close the Realm instance (Realm is using ref count based on the thread, so you need to ensure all instances on the thread get closed.) . I suggest you just wait for the PR i mentioned gets merged. – beeender Jan 25 '17 at 04:52
  • This currently is caused by https://github.com/realm/realm-java/issues/3685 . The problem is HandlerController's `private final ReferenceQueue> referenceQueueSyncRealmResults = new ReferenceQueue>();` removing the RealmResults only when it gets GC'd. – EpicPandaForce Jan 30 '17 at 10:28

0 Answers0