Check memory:
# NODE_OPTIONS=--max-old-space-size=4096
# node --max-old-space-size=4096 memory.js
node --max-old-space-size=4096 -e "console.log(JSON.stringify(v8.getHeapStatistics()));"
node -e "console.log(JSON.stringify(require('os').freemem()));"
node -e "console.log(JSON.stringify(require('os').totalmem()));"function logMemory() {
if (typeof process != 'undefined') {
console.log(`Node: ${process.memoryUsage().heapUsed / Math.pow(1000, 2)} MB`);
} else if (performance) {
console.log(`Browser: ${performance.memory.usedJSHeapSize / Math.pow(1000, 2)} MB`);
} else {
throw ('Where d-heck are you trying to run me?');
}
}
function measureMemory() {
const arraySize = 25 * Math.pow(1000, 2);
logMemory();
(function() {
const array1 = new Array(arraySize).fill(1.1);
logMemory();
})();
(function() {
const array2 = new Array(arraySize).fill(1);
logMemory()
})();
setTimeout(() => {
logMemory();
}, 5000);
}
measureMemory();https://gist.github.com/gorshkov-leonid/fec76ec4b829a1d63b1da7ea3ed255e1?permalink_comment_id=5002758#gistcomment-5002758 https://yonatankra.com/measuring-used-js-heap-size-in-nodejs/
the same is for chrome:
flags: