Memory-Usage Management
Memory-usage management is essential for preventing unnecessary resource usage, which affects not only performance but also battery life and overall end-user experience.
Having a well-thought memory management strategy ensures that your end-user environment remain memory-efficient and, as a result, your app more performant — faster load times, improved battery life, a responsive user interface, and so on.
For more information, see Platform Manual > CRUD Operations.
Depending on your use case, use either the evict method or the remove method, as well as applying soft-delete patterns to implement tools to help optimize memory usage in your app.
To mitigate the risk of memory leaks, performance degradataion, crashes, data loss, and, if applicable, reduced battery life, it is critical that you implement a methodical memory management strategy in your app.
When planning your approach to memory management in your app, use the following criteria to help you during the decision-making process:
Consideration | Recommendation |
Access frequency and relevance | Ensure memory is allocated only to the most relevant and frequently accessed documents by establishing an automatic process that evicts documents that are:
|
Timeseries data | Establish an automatic process to evict or remove time-based data older than a minimum of seven days. (Until expired, timeseries data remains accessible through local queries.) |
Permanent data loss | Apply careful consideration for your specific use case before invoking the remove API method to delete. For instance, removing documents may be useful for a scenario where your end user wants to remove a specific message from a chat conversation, such as a message sent. |
Common use cases for the evict method include:
- In a chat app context, the evict method is an effective memory management tool for a wide range of scenarios; for example:
- Efficiently manage memory-intensive tasks like fetching and displaying large binary files, such as a profile image stored in an attachment CRDT, upon an end-user's tap.
- Preventing memory bloat by discarding messages that are outdated and no longer relevant to the current chat session. For instance, evicting messages older than two days and images and videos that your end user tapped, viewed, and then closed.
- Implementing sophisticated loading techniques, such as loading only 20 messages per page in your paginated app and releasing messages from previous pages no longer visible to your end user.
- In a point-of-sale (PoS) app context, the evict method is helpful for a variety of scenarios; for example:
- Ensuring quick access to the most recent data, while archiving older transaction history for audit purposes.
- Periodically refreshing your inventory system and automatically clearing products that are no longer relevant, such as certain products only available during breakfast hours that become irrelevant after a certain time.