socket.write keeping reference to buffer?

85 views
Skip to first unread message

Jimb Esser

unread,
Feb 3, 2012, 1:36:26 AM2/3/12
to nodejs
The documentation on socket.write says that it queues all of the data
in kernel or user memory, but empirically it seems to be keeping a
reference to my buffer object I pass in so that if I make a change
after calling socket.write it may end up sending the changed data and
not what was passed to socket.write. Is this a bug, or expected
behavior and simply unclear documentation?

Ben Noordhuis

unread,
Feb 3, 2012, 6:27:48 PM2/3/12
to nod...@googlegroups.com

Expected behaviour (and arguably unclear documentation).

Node maintains the reference to prevent the GC from reclaiming your
buffer while the write is in progress. Don't touch the buffer again
until your write callback is called.

Reply all
Reply to author
Forward
0 new messages