-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
diagnostics_channel: fix diagnostics channel memory leak #45633
diagnostics_channel: fix diagnostics channel memory leak #45633
Conversation
ae3c2f9
to
2026e9c
Compare
LGTM. Not really how users are intended to use diagnostics_channel, but how users are meant to use things and how they actually use them doesn't always match, so seems like a reasonable fix to me. 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Could you add a test for this? Maybe by comparing the values of |
I think it is difficult to do that, do you have any idea? Thanks! |
I meant using the code you shared in the PR description with a slight modification - asserting that the value of // Flags: --expose-gc
'use strict';
// This test ensures that diagnostic channel references aren't leaked.
require('../common');
const { ok } = require('assert');
const { subscribe, unsubscribe } = require('diagnostics_channel');
function noop() {}
const heapUsedBefore = process.memoryUsage().heapUsed;
for (let i = 0; i < 1000000; i++) {
subscribe(String(i), noop);
unsubscribe(String(i), noop);
}
gc();
const heapUsedAfter = process.memoryUsage().heapUsed;
ok(heapUsedBefore >= heapUsedAfter); Is it difficult because it's too flaky? |
2026e9c
to
cf83822
Compare
Thanks for the suggestion. When i add the test(i = 1000000), i find the output is as follows.
But when i change the code
Then i take the snapshot before and after the loop. I find It takes up ten more megabytes of memory in |
cf83822
to
4fb75ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Landed in d579bc1 |
PR-URL: nodejs#45633 Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
PR-URL: #45633 Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
PR-URL: #45633 Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
PR-URL: #45633 Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
PR-URL: #45633 Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
PR-URL: #45633 Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
PR-URL: #45633 Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
fix diagnostics channel memory leak.
cc @Qard
make -j4 test
(UNIX), orvcbuild test
(Windows) passes