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. 😅 |
|
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
|
Landed in d579bc1 |
PR-URL: nodejs#45633 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
PR-URL: #45633 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
PR-URL: #45633 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
PR-URL: #45633 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
PR-URL: #45633 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
PR-URL: #45633 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
PR-URL: #45633 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>

fix diagnostics channel memory leak.
cc @Qard
make -j4 test(UNIX), orvcbuild test(Windows) passes