问题
I am toying with Realm and I always find that Realm.getInstance() is called during Activity create and instance closed in Activity destroy. May I know is there any side impact that keep only one instance create and open all the time until the application is closed?
回答1:
There is no Application onDestroy. Realm does the necessary caching internally, so it should be safe to call Realm.getInstance()/close() as many times as you want.
Trying to do your own caching will not make anything more efficient. You can read about how to control the Realm instance life cycles here:
https://realm.io/docs/java/latest/#controlling-the-lifecycle-of-realm-instances https://realm.io/docs/java/latest/#closing-realm-instances
来源:https://stackoverflow.com/questions/37692668/can-i-only-call-realm-getinstance-once-in-application