-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (36 loc) · 1.1 KB
/
index.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
var fs = require('fs');
var LOOP_LIMIT = 10e3;
var HALF_LOOP_LIMIT = LOOP_LIMIT/2;
function readFile() {
fs.readFile('file-to-read.txt', function (err, _content) {
// console.log("" + _content.length);
// = undefined; = null; delete - all those have no impact on memory usage here
var content = _content;
});
}
function readFileSync() {
// console.log("" + _content.length);
// = undefined; = null; delete - all those have no impact on memory usage here
var content = fs.readFileSync('file-to-read.txt');
}
function loop() {
for (var i = 0; i < LOOP_LIMIT; i++) {
readFile();
// readFileSync();
if (i === HALF_LOOP_LIMIT) {
console.log("run gc");
global.gc();
}
if (i === LOOP_LIMIT - 1) {
global.gc();
console.log("almost finished");
setInterval(function () {
global.gc();
console.log(new Date());
}, 1000);
}
}
}
// nice to have timeout for catching initial memory size
setTimeout(loop, 2000);
global.gc();