facebookexperimental / Recoil

Recoil is an experimental state management library for React apps. It provides several capabilities that are difficult to achieve with React alone, while being compatible with the newest features of React.
https://recoiljs.org/
MIT License
19.61k stars 1.19k forks source link

Memory management and garbage collection #954

Open 617976080 opened 3 years ago

617976080 commented 3 years ago

According to the demo website, selectorFamily is used for requests with parameters. And I saw this issue: https://github.com/facebookexperimental/Recoil/issues/863, atomFamily has memory leak problem. So does selectorFamily have a similar problem? Recoil repository called facebookexperimental/recoil, Whether I can use it for production environments? Thank you very much for developing Recoil. I am looking forward to using it in my project. Thank you.

davidmccabe commented 3 years ago

Automatic freeing of memory is coming in (hopefully) the near future. Recoil is both experimental and used in production; you should weigh the risks against the benefits for your specific app.

andrewagain commented 3 years ago

selectorFamily is actually much worse than atomFamily: it caches every input and every output for the lifetime of the app and there is no way to free this memory.

Recoil should only be used if your state tree atoms contain tiny bits of information. If you have a large list in an atom and then get() that atom in a selector: your app won't be able to last long before it crashes.

alxclark commented 2 years ago

@davidmccabe Does the team have an update on this ? 🙏🏼

drarmstr commented 2 years ago

selectorFamily is actually much worse than atomFamily: it caches every input and every output for the lifetime of the app and there is no way to free this memory.

The selector cache is now configurable, but the actual selectors/atoms in a family are not yet enabled to be garbage collected.