Recoil: Memory leak when using atomFamily/selectorFamily
Hello there,
The resources created by atomFamily
and selectorFamily
are not being properly freed when the specific key
changes or if the component using the related RecoilState<T>
unmounts.
Since I believe that memory management isn’t properly implemented yet, both utils should be marked as _UNSAFE
.
https://codesandbox.io/s/cranky-booth-penix?file=/src/App.js

About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 13
- Comments: 22 (9 by maintainers)
Commits related to this issue
- Support setting GKs in RecoilEnv (#2078) Summary: In https://github.com/facebookexperimental/Recoil/issues/366#issuecomment-1276638888, it was suggested that we could possibly use `RecoilEnv` to dyna... — committed to facebookexperimental/Recoil by impl 2 years ago
- Support setting GKs in RecoilEnv (#2078) Summary: In https://github.com/facebookexperimental/Recoil/issues/366#issuecomment-1276638888, it was suggested that we could possibly use `RecoilEnv` to dyna... — committed to snipershooter0701/Recoil by impl 2 years ago
Just FYI we are working on the memory issue with use of family utils, and should have something to announce about it in the near future.
Could this be related? I am getting this warning and cannot seem to figure out a way to get rid of it.
Maybe guys you could try something I did https://github.com/facebookexperimental/Recoil/issues/1864#issuecomment-1277399393
Any update on this?
@trivigy @ltwlf @chybisov @ianstormtaylor I don’t think the warning is related to the memory issue related to family utils. Let’s start a new thread to discuss that. It will be really helpful if anyone can provide a way to reproduce the issue you are describing and create a new issue with that.
The
RECOIL_GKS_ENABLED
has already been taken in and therecoil_memory_management_2020
appears to be set by default. What else should be done to eliminate memory leaks?That solution only controls the lifetime of the atom objects or the atom family closure which contains the dictionary of cached atom objects. While removing that would remove some minimal memory, the actual registered atom accounting structures, selectors, and selector caches would still be held in the runtime. If you would like to explore or finish memory management in Recoil use the
recoil_memory_managament_2020
feature flag inRecoil_gkx.js
Hi @mondaychen . Does the recent release (0.7.4) address any of this, or are those leaks elsewhere?
@mondaychen I think you’re right. I added a comment here: https://github.com/facebookexperimental/Recoil/issues/951#issuecomment-845958082
@mondaychen Still experience the same issue but I just squint my eye to not see so it wouldn’t bother me. 😆