Add resetRetrieveHandlers
to avoid memory leak
#215
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I haven't added docs as I don't think this is the correct way to do this...
Background:
Jest has a CLI flag called
--detectLeaks
which tries to sniff out memory leaks in your test suite.We discovered today that Jest itself seems to be leaking, and bisected it to jestjs/jest@3341d16. After fiddling a bit with it, I discovered that if I remove the whole
retrieveSourceMap
function from the options passed toinstall
, it doesn't complain about a leak. Just making the function be empty and always returnnull
still reported a leak.The only way I was able to find that lets us keep using
retrieveSourceMap
but not leak was to add the function added in this PR.It feels really hacky, so I'd love to find a way forward without needing this PR. 🙏
If you wanna mess around with fixes, to test in Jest just clone the repo, run
yarn
(followed byyarn watch
if you wanna make changes to Jest's code base and not just innode_modules
) and run./jest --detectLeaks diff --no-cache
. The diff I applied in Jest's code base to call the function added in this PR is this: