NodeJS: calling global.gc() doesn't reduce memory to minimum?

南笙酒味 提交于 2019-12-06 01:54:19

问题


To investigate memory leaks, I have setup a route that triggers global.gc() at every POST /gc

app.post('/gc', function(req, res){
     global.gc();
});

However, I've noticed that if I spam this request, it reduces the memory usage more and more each time. Shouldn't calling global.gc() once is enough to reduce the memory to minimum?

If so, why does calling multiple times consecutively reduces memory at every call?

(I'm using Node.js v0.12)


回答1:


At a very high level, V8 splits up GC into two parts. Looking for garbage to collect, and actually collecting the garbage. Calling gc() only does the second part, collecting already-found garbage.



来源:https://stackoverflow.com/questions/32178227/nodejs-calling-global-gc-doesnt-reduce-memory-to-minimum

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!