My React Native app loads some documents from Firestore and stores them locally in AsyncStorage. Depending on the user's app usage, this document collection can become quite large. It might happen that the documents of a specific user grow into the dozens of megabytes, together (e.g. 500 documents of about 100kB each).
(It might be an antipattern to use Firestore for documents which are that big. However, most use cases are dealing with a small number of small documents. Still, we need to make the app ready for power users)
The app uses AsyncStorage as a local cache of the documents' data. If the data is already there, nothing gets loaded from Firestore (at least initially). If not, then the data is loaded from Firestore and stored in AsyncStorage (we cannot use Firestore's cache because we transform the data when loading it, and we need a deterministic cache).
What we noticed is, when loading the data from Firestore, we end up with a huge memory consumption, even after there was enough time for Garbage Collection to collect everything. When loading the data from AsyncStorage, the memory consumption is much lower, even though we have the same data in memory.
To make sure that this memory is still retained (i.e. that my observation does not depend on Garbage Collection timing), I loaded about a Gigabyte of Firestore data onto a device. There were several memory warnings, and judging by the memory consumption observed, GC was working hard to collect as much as possible, but the memory consumption was still several Gigabytes higher than compared to when the data was loaded from AsyncStorage.
It seems that the Firestore client either has
Have I overlooked something? Is there some in-memory cache enabled by default? Does Firestore keep a copy of the data in memory to detect changes to the documents?