Do open realms close themselves after a period of inactivity? How are open Realms closed?


I’m building an app that has groups of users. At the start of the app, I open a Realm for every group the user is part of, and persist the Realms throughout the app with React Context Provider. When a user creates a new group, though, I need to open a Realm for that new group, and add it to the list of realms in the Context Provider component.

Currently, I’m opening a new Realm for each new group that the user creates, and then I’m manually sticking them inside the existing list of Realms in the Context Provider.

However, I’m wondering if it’s possible to “refresh” the Realms after a user creates a new group by simply calling the function that opens all the user’s realms at the beginning of the app and generating a new list of Realms. While this strategy would be the least amount of code, I’m worried that this strategy may produce memory leaks or performance issues since I am not sure how to close the existing, open Realms (or whether they even need to be closed) prior to “refreshing” the Realms.

Thank you for the help!

@Jerry_Wang It is definitely a best practice to close realms when you are done using them. If you are opening many realms, then I usually suggest a design pattern where the first view a user sees is a listView/recyclerView of all potential realms they could open - they could then select one which triggers the opening of this realm, they interact with it on another Activity, and then when they go back to the original listView which displays all the realms they have permission to access; you but a realm.close() in the onClose() lifecycle

You can sse an example of this in GH here -

With a tutorial here -

1 Like