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
Can't close realm instance #3321
Comments
So where else do you open new Realm instances? |
After your comment i've noticed that I was missing a close on a prevjously executed thread that was creating too much instances. So I've figured out that there's a limit to the realm instances, is that correct? Instead I must have other problem with my code |
There is no limit, just reference counting. However, leaving a background thread realm open is a very severe error. |
As @Zhuinden points out, leaving a background thread with an open Realm is problematic: https://realm.io/docs/java/latest/#large-realm-file-size |
Sure, that was just an oversight, now I have something like
Is it ok? To handle realm instance when I get an error I've added a while loop that close every instance of realm if an error occur
I haven't noticed issue with that at the moment, everything's working fine. Is there a better way to handle realm instance on a different thread? |
|
Thanks, everything's just working fine |
There is some fix? |
Currently I'm not having any problem, realm.close() is working as expected for me. I was having some threading problem (realm wasn't so good at that time, and I wasn't using it in the correct way). Normally I get the instance in the onCreate and close it in the onDestroy (or onStart and onStop with fragments). If realm is not closing, you probably did Realm.getDefaultInstance() more times than realm.close() |
Realm is only closed if the ref count decrease of close() makes If you open Realm multiple times with |
I'm having problem closing a realm instance. I'm doing some test, my code is the following:
output:
so realm is not closed by the .close() function. I'm using an handler only to test if the realm instance closes in some second, but nothing changes removing it.
I've also noticed that if after some time the realm instance closes I can't get an opened one simply by doing
realm = Realm.getDefaultInstance()
(the returned instance is already closed and return true forrealm.isClosed()
)The text was updated successfully, but these errors were encountered: