-
Notifications
You must be signed in to change notification settings - Fork 278
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
Potential memory leak in React SitecoreContextFactory #287
Comments
Hi @vtrbowman. thanks for great research :) There is indeed a leak because of no This test proves it
Here is heap diff for recent code and here when I add unsubscribe to unmount there still some problems or it is just my draft test, but clearly there is an improvement :) |
@vtrbowman Fixed in commit and released in v13.0.3. Feel free to reopen issue, if you will have this problem. |
Description
When running load testing on our react JSS app, we noticed memory usage steadily increasing over time. Upon investigation we saw that our JSS app when hosted using node SSR was using increasing memory.
We set up an OOTB JSS React setup and ran against that and noticed the same thing. Digging deeper into the memory dumps pre and post load test we were able to isolate a potential cause for this in the SitecoreContextFactory (https://github.com/Sitecore/jss/blob/dev/packages/sitecore-jss-react/src/components/SitecoreContext.tsx).
In this class the SitecoreContext components get subscribed to the factory changes using
subscribeToContext
. As far as we can tell however, theunsubscribeFromContext
method is never called, so the singleton instance of SitecoreContextFactory will be keeping references to the SitecoreContext for each request and never losing it's reference.I am by no means a node/react expert, so there may be a simple solution to this which I am unaware of, if we can just get confirmation of if this is an legitimate issue or not first, that would be great.
Expected behavior
We would expect all used component resources for a request to be cleared up after request is complete.
Steps To Reproduce
Possible Fix
Potentially can call
unsubscribeFromContext
when component is disposed (unmount?)Your Environment
Screenshots
The text was updated successfully, but these errors were encountered: