mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 16:46:56 +00:00

Previously we assume that the objects are GC'ed after one global.gc() returns, which is not necessarily always the case. Use gcUntil() to run GC multiple times if they are not GC'ed in the first time around. PR-URL: https://github.com/nodejs/node/pull/49053 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
20 lines
490 B
JavaScript
20 lines
490 B
JavaScript
// Flags: --expose-internals --expose-gc
|
|
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { internalBinding } = require('internal/test/binding');
|
|
const { WeakReference } = internalBinding('util');
|
|
|
|
let obj = { hello: 'world' };
|
|
const ref = new WeakReference(obj);
|
|
assert.strictEqual(ref.get(), obj);
|
|
|
|
async function main() {
|
|
obj = null;
|
|
await common.gcUntil(
|
|
'Reference is garbage collected',
|
|
() => ref.get() === undefined);
|
|
}
|
|
|
|
main();
|