1// Flags: --expose-gc 2'use strict'; 3const common = require('../common'); 4const onGC = require('../common/ongc'); 5const assert = require('assert'); 6const async_hooks = require('async_hooks'); 7const domain = require('domain'); 8const EventEmitter = require('events'); 9const isEnumerable = Function.call.bind(Object.prototype.propertyIsEnumerable); 10 11// This test makes sure that the (async id → domain) map which is part of the 12// domain module does not get in the way of garbage collection. 13// See: https://github.com/nodejs/node/issues/23862 14 15let d = domain.create(); 16d.run(() => { 17 const resource = new async_hooks.AsyncResource('TestResource'); 18 const emitter = new EventEmitter(); 19 20 d.remove(emitter); 21 d.add(emitter); 22 23 emitter.linkToResource = resource; 24 assert.strictEqual(emitter.domain, d); 25 assert.strictEqual(isEnumerable(emitter, 'domain'), false); 26 assert.strictEqual(resource.domain, d); 27 assert.strictEqual(isEnumerable(resource, 'domain'), false); 28 29 // This would otherwise be a circular chain now: 30 // emitter → resource → async id ⇒ domain → emitter. 31 // Make sure that all of these objects are released: 32 33 onGC(resource, { ongc: common.mustCall() }); 34 onGC(d, { ongc: common.mustCall() }); 35 onGC(emitter, { ongc: common.mustCall() }); 36}); 37 38d = null; 39global.gc(); 40