Excerpt from <node.js advanced Programming >
var buffer = new Buffer ("This is the content of my buffer");
var smallbuffer = Buffer.slice (8,19);
The problem here is that because the sub-buffers are copied from the parent buffer, the parent buffers will not be reclaimed by the garbage collector at the end of the operation, resulting in a memory leak problem;
New node. js version, re-improved the buffer interface, measured without this problem;
New Buffer (array) discarded by: v6.0.0
stability : 0 -obsolete : Use Buffer.from(array) instead.
function Testbuffer () { var strbuff = "Hello World,hello world,hello world,hello world,hello World,hello World,hello W Orld "; var arrbuff = new Array; var buff = Buffer.from (strbuff); for (var i = 0; i < buff.length; i++) { arrbuff.push (buff[i]); }; return buff;}; function Testloop () { setinterval (() = { var buff = Testbuffer (); var Buffson = Buff.slice (1, buff.length-1); Console.log (Buffson); }, 1); }; Testloop ();
Nodejs Buffer Memory Leak issue