Last active
October 26, 2017 19:54
-
-
Save suguru03/e2ecad8be3714b7c98727ab5def4807e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/* native Promise is used as default. | |
* You can try | |
* ``` | |
* node --expose_gc memory_leak_test.js | |
* ``` | |
* | |
* I'm just wondering if `expose_gc` has something problem. | |
* When the code is executed a lot of times, execution speed willb be slow down. | |
* | |
* Also, | |
* ``` | |
* node memory_leak_test.js | |
* ``` | |
* | |
* */ | |
// const Promise = require('bluebird'); | |
// const Promise = require('aigle'); | |
let count = 0; | |
(function exec() { | |
const start = Date.now(); | |
log(`START:[${++count}]`); | |
(function () { | |
const x = Promise.resolve(1); | |
for (let i = 0; i < 1000000; ++i) x.then(() => {}); | |
})(); | |
const diff = Date.now() - start; | |
log(`AFTER diff:${diff}`); | |
setTimeout(() => { | |
if (typeof gc === 'function') { | |
const start = Date.now(); | |
gc(); | |
const diff = Date.now() - start; | |
log(`AFTER GC. time:${diff}`); | |
} | |
setTimeout(exec, 100); | |
}, 100); | |
})(); | |
function log(label) { | |
console.log(process.memoryUsage().heapUsed, label); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment