This repository was archived by the owner on Sep 18, 2024. It is now read-only.
Updated deleting required files to fix memory leak#46
Merged
YorkAARGH merged 1 commit intoAnIdiotsGuide:masterfrom Jun 11, 2018
Merged
Updated deleting required files to fix memory leak#46YorkAARGH merged 1 commit intoAnIdiotsGuide:masterfrom
YorkAARGH merged 1 commit intoAnIdiotsGuide:masterfrom
Conversation
Simply delete require.cache[module] results in a memory leak after some time as the deleted module is still referenced in require.cache[module].parent.children, preventing it from GCing. The new function will allow it to GC properly.
kyranet
suggested changes
May 23, 2018
kyranet
left a comment
There was a problem hiding this comment.
I can reproduce this issue, good catch! I was unaware of this reloading issue.
| client.on(eventName, event.bind(null, client)); | ||
| const mod = require.cache[require.resolve(`./events/${file}`)]; | ||
| delete require.cache[require.resolve(`./events/${file}`)]; | ||
| for (let i = 0; i < mod.parent.children.length; i++) { |
There was a problem hiding this comment.
Use this instead:
const index = mod.parent.children.indexOf(mod);
if (index !== -1) mod.parent.children.splice(index, 1);
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Please describe the changes this PR makes and why it should be merged, as well as any and all proof of successful tests:
Simply delete require.cache[module] results in a memory leak after some time as the deleted module is still referenced in require.cache[module].parent.children, preventing it from GCing. The new function will allow it to GC properly.
Here is the previous unchanged file from chrome devtools:
https://i.imgur.com/59GlEja.png
After change, all the modules disappear after GC.
Semantic versioning classification: