答案是可以了,在启动node服务的时候使用–expose-gc flag
$ node --expose-gc file.js这样全局对象上就有了执行垃圾回收的函数
global.gc();推荐更安全的写法
function forceGC()
if (global.gc) {
global.gc();
} else {
console.warn('No GC hook! Start your program as `node --expose-gc file.js`.');
}
}最后给大家分享一下参考资料:
https://speakerdeck.com/addyosmani/javascript-memory-management-masterclass
//www.jb51.net/article/140005.htm
https://www.xarg.org/2016/06/forcing-garbage-collection-in-node-js-and-javascript/









