• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --expose-gc --no-deprecation
2'use strict';
3
4const common = require('../common');
5if (!common.hasCrypto)
6  common.skip('missing crypto');
7
8const assert = require('assert');
9const { createSecureContext } = require('tls');
10const { createSecurePair } = require('tls');
11
12const before = process.memoryUsage().external;
13{
14  const context = createSecureContext();
15  const options = {};
16  for (let i = 0; i < 1e4; i += 1)
17    createSecurePair(context, false, false, false, options).destroy();
18}
19setImmediate(() => {
20  global.gc();
21  const after = process.memoryUsage().external;
22
23  // It's not an exact science but a SecurePair grows .external by about 45 kB.
24  // Unless AdjustAmountOfExternalAllocatedMemory() is called on destruction,
25  // 10,000 instances make it grow by well over 400 MB.  Allow for some slop
26  // because objects like buffers also affect the external limit.
27  assert(after - before < 25 << 20);
28});
29