11cb0ef41Sopenharmony_ci// Flags: --expose-gc --no-deprecation
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciconst common = require('../common');
51cb0ef41Sopenharmony_ciif (!common.hasCrypto)
61cb0ef41Sopenharmony_ci  common.skip('missing crypto');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst assert = require('assert');
91cb0ef41Sopenharmony_ciconst { createSecureContext } = require('tls');
101cb0ef41Sopenharmony_ciconst { createSecurePair } = require('tls');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciconst before = process.memoryUsage().external;
131cb0ef41Sopenharmony_ci{
141cb0ef41Sopenharmony_ci  const context = createSecureContext();
151cb0ef41Sopenharmony_ci  const options = {};
161cb0ef41Sopenharmony_ci  for (let i = 0; i < 1e4; i += 1)
171cb0ef41Sopenharmony_ci    createSecurePair(context, false, false, false, options).destroy();
181cb0ef41Sopenharmony_ci}
191cb0ef41Sopenharmony_cisetImmediate(() => {
201cb0ef41Sopenharmony_ci  global.gc();
211cb0ef41Sopenharmony_ci  const after = process.memoryUsage().external;
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci  // It's not an exact science but a SecurePair grows .external by about 45 KiB.
241cb0ef41Sopenharmony_ci  // Unless AdjustAmountOfExternalAllocatedMemory() is called on destruction,
251cb0ef41Sopenharmony_ci  // 10,000 instances make it grow by well over 400 MiB.  Allow for some slop
261cb0ef41Sopenharmony_ci  // because objects like buffers also affect the external limit.
271cb0ef41Sopenharmony_ci  assert(after - before < 25 << 20);
281cb0ef41Sopenharmony_ci});
29