2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2012-11-24 15:24:36 +01:00
|
|
|
// Flags: --expose-gc
|
|
|
|
|
2016-12-31 00:38:06 +01:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const net = require('net');
|
2012-11-24 15:24:36 +01:00
|
|
|
|
2016-09-17 12:32:33 +02:00
|
|
|
assert.strictEqual(
|
|
|
|
typeof global.gc,
|
|
|
|
'function',
|
|
|
|
'Run this test with --expose-gc'
|
|
|
|
);
|
2012-11-24 15:24:36 +01:00
|
|
|
net.createServer(function() {}).listen(common.PORT);
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
let before = 0;
|
2016-07-13 01:47:32 +02:00
|
|
|
{
|
2012-11-24 15:24:36 +01:00
|
|
|
// 2**26 == 64M entries
|
2016-04-21 08:05:44 +02:00
|
|
|
global.gc();
|
2016-07-13 01:47:32 +02:00
|
|
|
let junk = [0];
|
|
|
|
for (let i = 0; i < 26; ++i) junk = junk.concat(junk);
|
2013-08-01 16:00:40 +02:00
|
|
|
before = process.memoryUsage().rss;
|
2012-11-24 15:24:36 +01:00
|
|
|
|
|
|
|
net.createConnection(common.PORT, '127.0.0.1', function() {
|
2016-08-17 06:11:22 +02:00
|
|
|
assert.notStrictEqual(junk.length, 0); // keep reference alive
|
2012-11-24 15:24:36 +01:00
|
|
|
setTimeout(done, 10);
|
2016-04-21 08:05:44 +02:00
|
|
|
global.gc();
|
2012-11-24 15:24:36 +01:00
|
|
|
});
|
2016-07-13 01:47:32 +02:00
|
|
|
}
|
2012-11-24 15:24:36 +01:00
|
|
|
|
|
|
|
function done() {
|
2016-04-21 08:05:44 +02:00
|
|
|
global.gc();
|
2017-01-08 14:19:00 +01:00
|
|
|
const after = process.memoryUsage().rss;
|
|
|
|
const reclaimed = (before - after) / 1024;
|
2012-11-24 15:24:36 +01:00
|
|
|
console.log('%d kB reclaimed', reclaimed);
|
2013-08-01 16:00:40 +02:00
|
|
|
assert(reclaimed > 128 * 1024); // It's around 256 MB on x64.
|
2012-11-24 15:24:36 +01:00
|
|
|
process.exit();
|
|
|
|
}
|