-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path6-gc.js
More file actions
40 lines (33 loc) · 878 Bytes
/
6-gc.js
File metadata and controls
40 lines (33 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
const memory = [];
let k = 0;
const bytesToMb = (bytes) => Math.round(bytes / 1000, 2) / 1000;
let collection = {};
const timer = setInterval(() => {
k++;
const key = 'globalVariable' + k;
collection[key] = new Array(1000).fill(key);
}, 5);
setInterval(() => {
console.clear();
const usage = process.memoryUsage();
const row = {
rss: bytesToMb(usage.rss), // process resident set size
heapTotal: bytesToMb(usage.heapTotal), // v8 heap allocated
heapUsed: bytesToMb(usage.heapUsed), // v8 heap used
external: bytesToMb(usage.external), // c++ allocated
stack: bytesToMb(usage.rss - usage.heapTotal), // stack
};
memory.push(row);
console.table(memory);
}, 1000);
setTimeout(() => {
clearInterval(timer);
if (global.gc) {
collection = {};
gc();
}
}, 10000);
setTimeout(() => {
process.exit(0);
}, 15000);