node/test/parallel/test-diagnostics-channel-memory-leak.js
theanarkh d579bc16b3
diagnostics_channel: fix diagnostics channel memory leak
PR-URL: https://github.com/nodejs/node/pull/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>
2022-11-29 10:58:43 +00:00

25 lines
514 B
JavaScript

// 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 < 1000; i++) {
subscribe(String(i), noop);
unsubscribe(String(i), noop);
}
global.gc();
const heapUsedAfter = process.memoryUsage().heapUsed;
ok(heapUsedBefore >= heapUsedAfter);