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)
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)
Share Improve this question edited Aug 24, 2015 at 13:27 Saitama asked Aug 24, 2015 at 8:59 SaitamaSaitama 4976 silver badges18 bronze badges 3- How (and when) do you measure memory consumption? – Bergi Commented Aug 24, 2015 at 13:39
-
@Bergi The application is connected to PM2, I measure the memory in real-time using
pm2 monit
. I waited for the memory to climb pretty high (1G). I then sendglobal.gc()
signal a few times. Each time it reduces memory by around 30-200Mb, until it hits an absolute minimum of ~80Mb. So it took like 10 calls for a full garbage collection, which contradicts what it should do (full garbage collection in one shot). – Saitama Commented Aug 24, 2015 at 21:21 - 2 This is due to the way how v8 gc works (sweeping) have a look into this great article about the gc jayconrod./posts/55/a-tour-of-v8-garbage-collection – Bernie Commented Nov 3, 2015 at 19:37
1 Answer
Reset to default 4At 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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744788540a4593774.html
评论列表(0条)