【发布时间】:2016-01-09 11:25:59
【问题描述】:
我正在将一个大的 js 模块加载到内存中,我想在不再需要释放 RAM 时释放它。
我用来测试的代码是这样的:
var lex = require('./lex.js'); //Big module (10M array)
setInterval(() => console.log(process.memoryUsage()), 1000);
setTimeout(() => {
lex = null;
delete require.cache[require.resolve('./lex.js')];
}, 5000);
// this script outputs each second
// { rss: 151756800, heapTotal: 131487520, heapUsed: 108843840 }
// { rss: 151760896, heapTotal: 131487520, heapUsed: 108850024 }
// ...
// and after 5 seconds there is no change
5 秒后,进程仍在使用与初始模块加载后相同的内存。
我做错了什么?谢谢!
【问题讨论】: