Skip to content

Instantly share code, notes, and snippets.

@Zhuinden
Last active July 11, 2017 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zhuinden/d6c5fb007b3c725e2c9625244d8d0daa to your computer and use it in GitHub Desktop.
Save Zhuinden/d6c5fb007b3c725e2c9625244d8d0daa to your computer and use it in GitHub Desktop.
Open RealmResults in transaction, not outside of it
try(Realm realm = Realm.getDefaultInstance()) {
final RealmResults<Dog> dogs = realm.where(Dog.class).findAll(); // NO
realm.executeTransaction(inRealm -> { // NO
for(Dog dog : dogs) { // NO
//...
}
});
}
////////////////////
try(Realm realm = Realm.getDefaultInstance()) {
realm.executeTransaction(inRealm -> { // YES
final RealmResults<Dog> dogs = inRealm.where(Dog.class).findAll(); // YES
for(Dog dog : dogs) { // YES (0.89.0+)
//...
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment