repl: keep reference count for process.on('newListener')#61895
Open
addaleax wants to merge 1 commit intonodejs:mainfrom
Open
repl: keep reference count for process.on('newListener')#61895addaleax wants to merge 1 commit intonodejs:mainfrom
process.on('newListener')#61895addaleax wants to merge 1 commit intonodejs:mainfrom
Conversation
When investigating a memory leak in one of our applications, we discovered that this listener holds on to a `REPLServer` instance and all heap objects transitively kept alive by it by capturing as part of its closure. It's cleaner to declare the listener outside of the `REPLServer` class and to actually clean it up properly when it is no longer required or meaningful, which is easily achieved through keeping a reference count.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61895 +/- ##
==========================================
- Coverage 91.70% 89.76% -1.94%
==========================================
Files 337 674 +337
Lines 140104 204899 +64795
Branches 21758 39381 +17623
==========================================
+ Hits 128484 183935 +55451
- Misses 11398 13237 +1839
- Partials 222 7727 +7505
🚀 New features to boost your workflow:
|
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When investigating a memory leak in one of our applications, we discovered that this listener holds on to a
REPLServerinstance and all heap objects transitively kept alive by it by capturing as part of its closure.It's cleaner to declare the listener outside of the
REPLServerclass and to actually clean it up properly when it is no longer required or meaningful, which is easily achieved through keeping a reference count.