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

Screen Shot 2020-06-19 at 12 07 12

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 13
  • Comments: 22 (9 by maintainers)

Commits related to this issue

Most upvoted comments

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.

Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.

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 the recoil_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 in Recoil_gkx.js

Hi @mondaychen . Does the recent release (0.7.4) address any of this, or are those leaks elsewhere?

@mondaychen Still experience the same issue but I just squint my eye to not see so it wouldn’t bother me. 😆