11cb0ef41Sopenharmony_ci// Flags: --expose-gc 21cb0ef41Sopenharmony_ci'use strict'; 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ci// This test ensures that diagnostic channel references aren't leaked. 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_cirequire('../common'); 71cb0ef41Sopenharmony_ciconst { ok } = require('assert'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst { subscribe, unsubscribe } = require('diagnostics_channel'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_cifunction noop() {} 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst heapUsedBefore = process.memoryUsage().heapUsed; 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_cifor (let i = 0; i < 1000; i++) { 161cb0ef41Sopenharmony_ci subscribe(String(i), noop); 171cb0ef41Sopenharmony_ci unsubscribe(String(i), noop); 181cb0ef41Sopenharmony_ci} 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciglobal.gc(); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciconst heapUsedAfter = process.memoryUsage().heapUsed; 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ciok(heapUsedBefore >= heapUsedAfter); 25