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

Clear tableTypes collection when TablePage unmounts to avoid memory leak #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Arooba-git
Copy link

Hello 👋
As part of our project, we are using Facebook's new Memlab tool to detect memory leaks in SPA applications.
While running the tool and analyzing the code of react-reduction, we saw that your project does a very good job of ensuring that all async operations are cancelled when the component unmounts. However, as per Memlab execution results, we found a dangling collection that was causing the memory to leak (screenshots below).

[before]
Screen Shot 2023-01-28 at 4 47 49 PM


Hence we added the fix by clearing the collection on unmount, and you can see the heap size and # of leaks reducing noticeably:

Screen Shot 2023-01-28 at 6 25 33 PM

Note: We used splice instead of the more conventional .length=0, to cater for any future modifications where tableTypes may have a length property but is not assignable.

You can analyze this and other potential leak sources, if you like, by running Memlab with a scenario file covering the maximum # of use cases.
Following is a sample of the scenario file we used (it needs to be a .js file but attaching here in .txt form):

react-reduction-memlab-scenario.txt

Note that some other reported leaks (in Memlab) originated from React's internal objects, and hence were ignored.

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

Successfully merging this pull request may close these issues.

1 participant