New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Realm Observables now holds a Realm instance reference #2364
Conversation
@@ -311,7 +336,7 @@ public void call(DynamicRealm rxRealm) { | |||
@UiThreadTest | |||
public void unsubscribe() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change name to unsubscribe_onWrongThread
?
Besides some minor comments, 👍 |
0663ac3
to
7ea8745
Compare
👍 |
return Observable.create(new Observable.OnSubscribe<Realm>() { | ||
@Override | ||
public void call(final Subscriber<? super Realm> subscriber) { | ||
// Get instance to make sure that the Realm is open for as long as the | ||
// Observable is subscribed to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to -> to it
just minor comments issues, but they happen in a bunch of places. Otherwise this looks good to me 👍 |
} | ||
})); | ||
|
||
// Immediately call onNext with the current value, as due to Realms auto-update, it will be the latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Realm's"
7ea8745
to
389828d
Compare
Realm Observables now holds a Realm instance reference
Fixes #2357
Due to how RxJava executes the chain of Observables, currently it isn't possible to use
doOnUnsubscribe()
to close Realm instances as the side-effect is triggered before the Observable is truly unsubscribed to (crashing our 'removeChangeListeners() method).This PR changes the current implementation so each Observable also holds onto a Realm instance prevent the Realm from being fully closed until the Observable is unsubscribed to. This means we can now guarantee that the Realm is alive for as long as the Observable is subscribed to. The only downside is that you risk leaking Realm instances if you forget to unsubscribe, but that would be a memory leak in any case.
@realm/java
/cc @lucamtudor