Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak because of memoizedFunction #307

Open
faridsaid20 opened this issue Mar 1, 2024 · 0 comments
Open

Memory leak because of memoizedFunction #307

faridsaid20 opened this issue Mar 1, 2024 · 0 comments

Comments

@faridsaid20
Copy link

Hi,

I have noticed a memory leak because of caching of element types in tryFixCtx function in fixContext.js file.
As I see, tryFixCtx caches in a Map all the types that it gets.
It continues forever even if the element of that type is unmounted long time ago.
This often leads to detached references to nodes and thus memory leak.
In our project it leads to 600 nodes added on each visit to a page. We don't event need to use keepAlive, on that page.

I already prepared a solution which you could consider. But sadly I cannot create Pull Request here, so sharing screenshots instead.

Step 1. Add weakMemoize funciton which is 99% copy of memoize, but using WeakMap instead.
Notice added try catch, it was needed because WeakMap cannot have symbols as their keys.

image

Step 2. Use weakMemoize function instead of memoize

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant