前端内存查看的几种方式

第一、浏览器中  window.performance

 第二、node 环境中 用 process.memoryUsage()

// 模仿内存回收 
var size = 20 * 1024 * 1024
var arrall = []

function getme() {
    var mem = process.memoryUsage()
    console.log(mem)
    var format = function(bytes) {
        return (bytes / 1024 / 1024).toFixed(2) + 'MB';
    }
    console.log('heapTotal: ' + format(mem.heapTotal) + 'heapUsed: ' + format(mem.heapUsed))
}

getme()

// v8引擎只有1.4g内存可以支配
for (var i = 0; i < 20; i++) {
    if (arrall.length > 4) {
        arrall.shift()
    }
    arrall.push(new Array(size))
    getme()
}

猜你喜欢

转载自www.cnblogs.com/sweet-ice/p/12047622.html