pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21.18k stars 1.04k forks source link

Question regarding memory use of RxCollection #6361

Open alexisskodak opened 3 weeks ago

alexisskodak commented 3 weeks ago

I am having trouble understanding why long lived RxCollection instances store all of the data in memory.

The documentation states that the RxCollection instance should be destroyed with the.destroy() method in order to free up memory, and it works. However it is still unclear to me why the RxCollection instances load all of the data into memory in the first place.

here's a basic flow explaining how I am currently using it:

Without destorying the RxCollections, the JS Heap is reaching around 1.5GB on certain pages which makes the app crash on certain devices.

is this something that can be adjusted through configuration ? If not, what is the intended use of this ? Maybe I'm using RxDB incorrectly ?

Thanks

pubkey commented 3 weeks ago

When documents are fetched from the storage, their RxDocument instance is cached and reused. We use a WeakRef for that and the documents get cleared from cache after some time if they are no longer used. If that does not work, you likely created a memory leak my referencing to all these documents somehow.

alexisskodak commented 3 weeks ago

are you saying that calling the destroy method is not really 'needed' and the cached documents should be garbage collected eventually ?

pubkey commented 3 weeks ago

yes

stale[bot] commented 2 weeks ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed soon. Please update it or it may be closed to keep our repository organized. The best way is to add some more information or make a pull request with a test case. Also you might get help in fixing it at the RxDB Community Chat If you know you will continue working on this, just write any message to the issue (like "ping") to remove the stale tag.