mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
0b6b2a4dc7
PR-URL: https://github.com/nodejs/node/pull/54355 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
20 lines
452 B
JavaScript
20 lines
452 B
JavaScript
// Flags: --expose-internals --expose-gc
|
|
'use strict';
|
|
require('../common');
|
|
const { gcUntil } = require('../common/gc');
|
|
const assert = require('assert');
|
|
const { WeakReference } = require('internal/util');
|
|
|
|
let obj = { hello: 'world' };
|
|
const ref = new WeakReference(obj);
|
|
assert.strictEqual(ref.get(), obj);
|
|
|
|
async function main() {
|
|
obj = null;
|
|
await gcUntil(
|
|
'Reference is garbage collected',
|
|
() => ref.get() === undefined);
|
|
}
|
|
|
|
main();
|