react-activation icon indicating copy to clipboard operation
react-activation copied to clipboard

Memory leak because of memoizedFunction

Open faridsaid20 opened this issue 1 year ago • 0 comments
trafficstars

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

faridsaid20 avatar Mar 01 '24 00:03 faridsaid20