Realm realm = Realm.getInstance(context); myObject = realm.where(...).findFirst(); realm.close(); // From this moment on using realm or myObject is illegal myVar = myObject.getFiesd(); // BOOM!
--
You received this message because you are subscribed to the Google Groups "Realm Java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-java+...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-java/a4f92c8d-efa0-4d0f-8a05-75e6cdea6b97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thank you for quick reply! Hm.. ok, I will try not to close Realm when
reading right after reading... but how to make sure I'm closing Realm after
reading... I'm trying not to mix Models with Data AccessLayer..
Another idea about multithreading. What if I surround all CRUD operation
with try\catch and if exception is IllegalStateException - get Realm for
this Thread and repeat operation:
@Override
public void create(@Nullable T object) {
try {
*createRealm*(object);
} catch (IllegalStateException ex) {
mRealm = Realm.getInstance(getContext());
*createRealm*(object);
}
}
четвер, 5 лютого 2015 р. 14:30:01 UTC+2 користувач Mykhailo Kovalyk написав:
On Thu, Feb 5, 2015 at 12:48 PM UTC, Help <he...@realm.io> wrote:
Hello Mykhailo,
unfortunately it's a bad pattern you are trying to use for several reasons:
1) Opening and closing realms is a relatively expensive operation, especially it's it's he first Realm being instantiated in a thread.
2) As the exception suggests doind this is not legal:Realm realm = Realm.getInstance(context); myObject = realm.where(...).findFirst(); realm.close(); // From this moment on using realm or myObject is illegal myVar = myObject.getFiesd(); // BOOM!
This happens because Realm data is never copied to memory and is always accessed in real time from the Realm. This is one of the features that gives Realm its speed and consistency.
What is your specific use case? Maybe we can help you find a better way to proceed.
--
Emanuele Zattin
On Thu, Feb 5, 2015 at 12:30 PM UTC, Mykhailo Kovalyk <mishak...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "Realm Java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-java+...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-java/a4f92c8d-efa0-4d0f-8a05-75e6cdea6b97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Problem: Exception: IllegalStateException: This Realm instance has already been closed, making it unusable.