Saitama
Saitama

Reputation: 497

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

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)

Upvotes: 8

Views: 6953

Answers (1)

snek
snek

Reputation: 2161

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.

Upvotes: 4

Related Questions