In order to understand the memory usage pattern of NodeJS's V8 engine, I wrote a simple web program as shown below:
contents of server.js:
var http = require("http");
var server = http.createServer(function(req, res) {
res.write("Hello World");
res.end();
});
server.listen(3000);
When the program is launched using node server.js, the initial memory snapshot is as below:

After I kept making multiple URL hits to this server, I could see a pattern of increased heap usage. To be more precise, for every 6 or 7 hits, there is an increase of 4K. I kept repeating the hits continuously for about 2 minutes, then this is the snapshot.

I didn't see any eventual decrease in heap usage, even if I kept it idle without load.
My question is:
Is this a normal behavior, or there is a memory leak in nodeJS? Or, am I understanding or interpreting it incorrectly?
Node uses V8 under the hood, so the answer to this question most likely applies: How does V8 manage its heap?
The code appears to be valid, so to test you could write a small application to repeatedly call your api and then examine Node's memory while running. Use this to help detect possible leakage (if there is any over 5 consecutive runs of the garbage collector): http://www.nearform.com/nodecrunch/self-detect-memory-leak-node/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With