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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -