joyent/node — Issue #2313: Memory leak on UDP send and TCP write
Author: morkai
Created: 2011-12-11 14:44:18+00:00
State: open

Repeateadly calling `udpSocket.send()` or `tcpSocket.write()` increases memory usage (even when sending the same buffer). Starting from 0.5.6 (libuv is turn on by default) something is not freed up and memory usage does not go down after closing the socket, doing something else and waiting 200+ seconds.

I've prepared simple scripts and run them against different node.js versions: [gist](https://gist.github.com/1460809) or [zip](http://lukasz.walukiewicz.eu/files/nodejs-socket-send-leak.zip)

After some time, versions lower than or equal to 0.5.5 sit at <13 MB, and versions greater than or equal to 0.5.6 - at 40-90 MB.

To run UDP test:

node --expose-gc udp-client.js

To run TCP test:

node tcp-server.js
node --expose-gc tcp-client.js

After creating the socket, 250k messages are sent one after another (after every 100k message, waits 5 seconds), then socket is closed and a big string is created (twice).

And node for Windows uses 2-3x more memory.

(My knowledge of C++ is limited to printing Hello World, but...) Maybe it is `uv_buf_t buf` at [udp_wrap.cc:213](https://github.com/joyent/node/blob/master/src/udp_wrap.cc#L213) in `UDPWrap::DoSend()` that is not released as it is in `UDPWrap::OnRecv()`.