android - How to close realm opened by Realm.getDefaultInstance? -
i using realm store , retrieve data. when open realm store data like:
realm realm = realm.getdefaultinstance(); realm.begintransaction(); // copy object realm realm.copytorealm(myobject); realm.committransaction(); realm.close();
in above case closing realm.
but when retrieving data like:
realmresults<myclass> results = realm.getdefaultinstance().where(myclass.class).findall();
how close realm? need closed?
doing one-liners means cannot close realm, advice against that.
not closing realm in best case cause leak memory , have higher chance of being killed system if in background. worst case see high increase in disk usage because realm has keep track of versions of opened realm instances (due being mvcc database).
i highly advice using first pattern. more information controlling realm instances can read this: https://realm.io/docs/java/latest/#controlling-the-lifecycle-of-realm-instances , https://realm.io/news/threading-deep-dive/
Comments
Post a Comment