-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
47 lines (40 loc) · 925 Bytes
/
test.js
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
41
42
43
44
/**
* 测试gc
* node --expose-gc test.js
*/
function info() {
const format = function (bytes) {
return (bytes / 1024 / 1024).toFixed(2) + ' MB';
};
const memoryUsage = process.memoryUsage();
console.log(JSON.stringify({
rss: format(memoryUsage.rss),
heapTotal: format(memoryUsage.heapTotal),
heapUsed: format(memoryUsage.heapUsed),
external: format(memoryUsage.external),
}));
}
let gJobs = [];
(async ()=>{
console.log(1);
info()
for(let i = 0;i< 10;i++){
let job = {
uuid: '123',
step: [{a:1,b:2},{a:11,b:22}],
status: 0,
arr: new Array(10*1024*1024)
};
gJobs.push(job);
console.log('---')
info()
}
global.gc();
for(let i = 0;i< 10;i++){
gJobs.shift()
info()
}
global.gc();
console.log('-end--')
info()
})()